git自动将文件从CRLF转换为LF不起作用

Xia*_* Wu 5 git git-config

在我们的系统上,我们曾经能够将所有CRLF转换为LF,同时将文件提交到git中.现在这个功能消失了.

这就是我所做的:

git config --global core.autocrlf false
Run Code Online (Sandbox Code Playgroud)

完成上述操作后,我使用以下命令检查:

git config --list
Run Code Online (Sandbox Code Playgroud)

结果是:

... 
core.autocrlf=input
...
core.autocrlf=false
...
Run Code Online (Sandbox Code Playgroud)

这非常令人费解.虽然有两个条目core.autocrlf,第一个是core.autocrlf=input?如果我未core.autocrlf使用:

git config --global --unset core.autocrlf
Run Code Online (Sandbox Code Playgroud)

当我列出git config时,我仍然得到一个条目:

core.autocrlf=input
Run Code Online (Sandbox Code Playgroud)

第2步:在我做完之后git config --global core.autocrlf false,我添加* text=auto.gitattributes文件中.

但是git仍然没有为我自动转换换行符.

小智 9

从git1.8.1rc1开始:

"git config --get"用于诊断同一个配置文件中同一个变量的多个定义是否存在错误,但它现在应用了内部配置逻辑使用的"最后一个胜利"规则

所以你的第二个设置适用.

有关core.autoctrlf选项的更多说明:

如果您使用的是Windows计算机,请将其设置为true - 这会在您签出代码时将LF结尾转换为CRLF:

$ git config --global core.autocrlf true
Run Code Online (Sandbox Code Playgroud)

您可以告诉Git在提交时将CRLF转换为LF,但不能通过将core.autocrlf设置为输入来反转:

$ git config --global core.autocrlf input
Run Code Online (Sandbox Code Playgroud)

如果您是Windows程序员,只执行Windows项目,则可以关闭此功能,通过将config值设置为false来记录存储库中的回车:

$ git config --global core.autocrlf false
Run Code Online (Sandbox Code Playgroud)

更多解释:http: //git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#Formatting-and-Whitespace