.gitattributes在mac和windows上无法正常工作

时间:2016-10-12 09:28:17

标签: windows git macos gitattributes end-of-line

在我的项目中,我使用的是具有不同操作系统的计算机,一个是Mac,第二个是Windows。当我使用git时,每个更改都会显示为整个文档更改。原因是这两个OS中的行尾不同。我读了这个https://help.github.com/articles/dealing-with-line-endings/并在根文件夹中创建了一个.gitattributes文件,但问题仍然存在。这是我的.gitattributes文件:

# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.

*.css text
*.html text
*.js text

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary

我不知道它为什么不起作用,因为我之前尝试过很多配置。

2 个答案:

答案 0 :(得分:4)

.gitattributes文件应该与第一次提交一起添加。如果你添加一些提交,你需要明确标准化所有现有文件。

$ rm .git/index     # Remove the index to force Git to
$ git reset         # re-scan the working directory
$ git status        # Show files that will be normalized
$ git add -u
$ git commit -m "Introduce end-of-line normalization"

请参阅https://git-scm.com/docs/gitattributes

答案 1 :(得分:0)

如果第一次提交时未添加.gitattributes文件,则应执行以下操作以在本地应用属性:

  1. 转到存储库的根目录

  2. 检查状态:

    git状态

  3. 如果显示“什么也没提交,工作树就干净了”,请执行:

    git rm --cached -r。

    git reset --hard

答案基于https://dev.to/deadlybyte/please-add-gitattributes-to-your-git-repository-1jld