git autocrlf input会将行尾换行符从LF转换为CRLF吗?

8

git config --global core.autocrlf input

根据github的帮助页面,这应该配置git在提交时将所有行结束符转换为LF。

但是当我提交到我的repo时,会得到以下输出。

> git commit -am "test commit"
warning: LF will be replaced by CRLF in .htaccess.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .htaccess.
The file will have its original line endings in your working directory.
[release/4.2 27bad5b] test commit
warning: LF will be replaced by CRLF in .htaccess.
The file will have its original line endings in your working directory.
 1 files changed, 1 insertions(+), 1 deletions(-)

我随后检查了我的配置文件,以确定autocrlf选项是否正确设置,并且它是正确的。

> git config -l | grep "crlf"
core.autocrlf=input

为什么git会将我的LF转换为CRLF而不是我想要的反向转换呢?它为什么会发出3次警告?是因为它发现了3个需要替换的实例吗?为什么在输出提交哈希后只警告我一次呢?我很困惑(记录一下,我正在使用Mac)

(作为一个注释,该 GitHub 页面仅在非 Windows 选项卡上提到“autocrlf=input”...) - rogerdpack
1个回答

13

在长时间处理行结尾之后,我不会允许任何工具(包括版本控制系统)更改它们。

我现在使用 autocrlf falsecore.whitespace cr-at-eol。这可以消除差异输出中的令人讨厌的 ^M。这只是git添加的一项突出显示,用于显示像行尾处的额外空格或制表符之前等恶心的东西。

希望您也能够这样做,并永远解决行结尾问题。


Adam的建议完全正确。当我在使用包含混合换行符的旧版内部网络内容的大型repo进行初始化时(这就是autocrlf失败的原因),我遇到了类似的问题。在这里关闭autocrlf是最明智的选择。 - Blackcoat

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接