在 Git for Windows 中使用 lf 换行符的正确方法是设置 core.autocrlf 为 false:

git config --global core.autocrlf false
如果使用 msysgit,则需要执行此操作,因为它将其设置为 true。

看到这里,你可以关闭这篇文章了,现在 git 不会做任何换行符转换。如果你希望规范 repo 文件中的换行符,请在 repo 目录中添加 .gitattributes,内容为:

* text=auto

并设置 core.eol 为 lf:

git config --global core.eol lf