使用autocrlf = false的Git仍然会产生"警告:CRLF将被LF替换"消息

Cur*_*son 5 git core.autocrlf

我在Ubuntu 14.04上使用Git版本1.9.1.

我已经core.autocrlf在一个带有DOS格式和Unix格式文件的新repo中测试了这种行为,并确认git add使用autocrlf=truedo,正如预期的那样,LF will be replaced by CRLF in ...为Unix格式文件生成一条警告:消息,并且在任何文件时都不生成消息autocrlf=false.(在这种情况下,我不清楚为什么它决定在回购中使用DOS行结尾而不是Unix行,但我不确定这在哪里很重要.)

然而,在另一个回购中,尽管有autocrlf=true,它一直告诉我它将转换一些文件:

$ git config core.autocrlf
false
$ git add lib/node_modules/pulp/node_modules/webpack/node_modules/webpack-core/node_modules/source-list-map/test/fixtures/from-to-tests/null-source.input.map
warning: CRLF will be replaced by LF in lib/node_modules/pulp/node_modules/webpack/node_modules/webpack-core/node_modules/source-list-map/test/fixtures/from-to-tests/null-source.input.map.
The file will have its original line endings in your working directory.
$
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么这样做.我正在寻找问题的解释或如何调试它的线索.

补充说明:

  • 不,.gitattributes回购中没有文件.但它提出了一个有趣的观点,如果autocrlf设置为false会有所不同吗?
  • 不,我只是仔细检查,文件在每个0x0d后有一个0x0a,在每个0x0a之前有一个0x0d.

Von*_*onC 3

首先,设置core.autocrlffalse通常是一个好主意:请参阅“处理以 GIT 结尾的行”。

其次,确保core.autocrlf在要添加的文件的父文件夹中查询时实际上为 false:

git -C lib/node_modules/[...]/fixtures/from-to-tests/ config core.autocrlf
Run Code Online (Sandbox Code Playgroud)

还检查问题今天仍然存在(2018 年 6 月,Git 2.17.1)

第三,该警告是Steffen Prohaska (sprohaska)于 2008 年 2 月 (Git v1.5.5)提交21e5ad5中引入的。

对于意外分类为文本的二进制文件,转换可能会损坏数据。

您可能检查了文本文件,但忽略了二进制文件。

最后,自 Git 2.8(2016 年 3 月)起,检测受 eol 设置影响的文件的一个好方法是使用:

git ls-files --eol
Run Code Online (Sandbox Code Playgroud)

请参阅“ git 显示修改的文件,但我没有更改任何内容并且git reset不起作用”。