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
但这些似乎没有做任何事情.有谁知道如何关闭警告?
谢谢.
我只是autocrlf=true在.git/config文件中使用来涵盖Windows中的大多数情况.根据新的源文件,偶尔会有警告.
如果您有不遵循该方案的特殊文件,请为它们单独设置.gitattributes,例如我有Matlab文件*.m eol=lf.
我用这种方式:
git config
core.autocrlf命令用于更改Git处理行尾的方式。它仅需一个参数。在Windows上,您只需传递
true到配置即可。例如:Run Code Online (Sandbox Code Playgroud)$ git config --global core.autocrlf true # Configure Git on Windows to properly handle line endings您还可以提供一个特殊的--global标志,使Git在计算机上每个本地Git存储库中对行尾使用相同的设置。
设置
core.autocrlf选项并提交 .gitattributes文件后,您可能会发现Git想要提交尚未修改的文件。此时,Git渴望为您更改每个文件的行尾。自动配置存储库行尾的最佳方法是,首先使用Git备份文件,删除存储库中的每个文件(.git目录除外),然后立即恢复所有文件。将当前文件保存在Git中,这样就不会丢失任何工作。
Run Code Online (Sandbox Code Playgroud)$ git add . -u $ git commit -m "Saving files before refreshing line endings"从Git的索引中删除每个文件。
Run Code Online (Sandbox Code Playgroud)$ git rm --cached -r .重写Git索引以拾取所有新行结尾。
Run Code Online (Sandbox Code Playgroud)$ 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"
来源:https : //help.github.com/articles/dealing-with-line-endings/