如何关闭Git警告"LF将被CRLF取代"?

B S*_*ven 9 git config newline lf

我在Windows上工作,但也可以在Unix上工作,所以我不需要存储Windows行结尾.我只想抑制警告.

我发现了这些相关的Stack Overflow问题:
git关闭"LF将被CRLF替换"警告
git,空白错误,静噪和autocrlf,最终的答案

我试过:
git config core.whitespace cr-at-eol false
git config core.whitespace cr-at-eol true
git config core.whitespace cr-at-eol nowarn

但这些似乎没有做任何事情.有谁知道如何关闭警告?

谢谢.

Phi*_*ley 7

我只是autocrlf=true.git/config文件中使用来涵盖Windows中的大多数情况.根据新的源文件,偶尔会有警告.

如果您有不遵循该方案的特殊文件,请为它们单独设置.gitattributes,例如我有Matlab文件*.m eol=lf.

  • 为了详细说明像我这样的 git 新手:文件“config”位于 .git 目录中。在 Windows 上,设置了目录的“隐藏”属性。 (2认同)

Jul*_*ova 5

我用这种方式:

git config core.autocrlf命令用于更改Git处理行尾的方式。它仅需一个参数。

在Windows上,您只需传递true到配置即可。例如:

$ git config --global core.autocrlf true    
# Configure Git on Windows to properly handle line endings
Run Code Online (Sandbox Code Playgroud)

您还可以提供一个特殊的--global标志,使Git在计算机上每个本地Git存储库中对行尾使用相同的设置。

设置core.autocrlf选项并提交 .gitattributes文件后,您可能会发现Git想要提交尚未修改的文件。此时,Git渴望为您更改每个文件的行尾。

自动配置存储库行尾的最佳方法是,首先使用Git备份文件,删除存储库中的每个文件(.git目录除外),然后立即恢复所有文件。将当前文件保存在Git中,这样就不会丢失任何工作。

$ git add . -u
$ git commit -m "Saving files before refreshing line endings"
Run Code Online (Sandbox Code Playgroud)

从Git的索引中删除每个文件。

$ git rm --cached -r .
Run Code Online (Sandbox Code Playgroud)

重写Git索引以拾取所有新行结尾。

$ git reset --hard
Run Code Online (Sandbox Code Playgroud)

重新添加所有更改的文件,并准备提交。这是您检查哪些文件(如果有)未更改的机会。

$ git add .
# It is perfectly safe to see a lot of messages here that read
# "warning: CRLF will be replaced by LF in file."
Run Code Online (Sandbox Code Playgroud)

将更改提交到存储库。

$ git commit -m "Normalize all the line endings"
Run Code Online (Sandbox Code Playgroud)

来源:https : //help.github.com/articles/dealing-with-line-endings/