当 autocrlf 为 false 且文本未指定时,Git 仍显示“LF 将被 CRLF 替换”警告

Hel*_*ele 5 windows git

我有一个只能在 Windows 上使用的存储库。而且我希望源代码管理不会以任何方式修改我的文件的内容。

core.autocrlf在全局设置中设置为 false 并验证不存在本地回购覆盖。我发现我的 repo 中有一个现有的 .gitattributes 文件,* text=auto它是唯一的条目。所以我删除了 .gitattributes 文件。通过阅读文档,我的理解是这应该导致text未指定,并将遵循为core.autocrlf.

但是,当我暂存我的文件时,我仍然收到以下错误:

LF will be replaced by CRLF in MyProject/src/static/images/logo.svg.
The file will have its original line endings in your working directory.
Run Code Online (Sandbox Code Playgroud)

如果我理解正确,有些东西仍然会修改我的文件。它是什么,我该如何阻止它?

Von*_*onC 4

首先,正如我在“ Windows git \xe2\x80\x9cwarning:LF将被CRLF\xe2\x80\x9d替换,警告尾部向后吗? ”中提到的,请确保:

\n
    \n
  • 使用最新的Windows 版 Git(至少超过 2.19)
  • \n
  • 设置git config --global core.autocrlf false(您已经这样做了,正如您的问题中所指定的:好)
    \n由于您没有.gitattributes文件,因此svg文件没有文本属性:\n
    \n

    如果text未指定该属性,Git 将使用core.autocrlf配置变量来确定是否应转换文件。

    \n
    \n
  • \n
\n

其次,检查是否add --renormalize有帮助

\n
git add --renormalize .\ngit commit -m "Introduce end-of-line final normalization if needed"\ngit push\n
Run Code Online (Sandbox Code Playgroud)\n

然后检查存储库的新克隆是否仍会显示相同的消息。

\n
\n

注意:警告消息已随 Git 2.37 (Q3 2022) 更改

\n