Git - 使用 .gitattributes 强制一致的行结尾时的奇怪之处

Git - Weirdness when using .gitattributes to force consistent line endings

所以,我最近在我们的一个存储库中添加了一个 .gitattributes 文件,以尝试强制使用一致的行结尾:

  # All Perl Sources should use Unix style line endings
  *.pl text eol=lf
  *.pm text eol=lf

但我自己和许多其他开发人员都遇到了很多 "phantom changes",其中 git 似乎将文件检测为 "changed",即使没有任何变化。每行显示为添加,然后删除。

我怀疑它对行结尾感到困惑(因此检测到每一行都已更改),但这里的奇怪之处在于:

有没有人遇到过这个问题,有没有办法避免或解决这个问题?

With Git 2.16以上,至少做一次:

git add --renormalize .
git commit -m "normalize eol files"
git push

然后尝试在其他地方克隆您的存储库,并检查 git status 是否按预期运行。

确保您没有将 core.autocrlf 设置为 true

git config core.autocrlf

而且你可以test for your files eol style