4

在我的项目中,我使用具有不同操作系统的计算机,一个是 Mac,第二个是 Windows。当我使用 git 时,每个更改都显示为整个文档更改。原因是这两个操作系统的行尾不同。我阅读了此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

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

4

2 回答 2

9

.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

于 2016-10-13T21:47:15.037 回答
2

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

  1. 转到存储库的根目录

  2. 检查状态:

    状态

  3. 如果它说“没有提交,工作树干净”,执行:

    git rm --cached -r 。

    git reset --hard

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

于 2020-10-30T13:47:43.170 回答