使用 Git,如何关闭“LF 将被 CRLF 替换”警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6500880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
With Git, how do I turn off the "LF will be replaced by CRLF" warning
提问by sent-hil
With Git, when using the autocrlf = true
flag, a warning is still given when line-endings are changed.
使用 Git 时,当使用该autocrlf = true
标志时,在更改行尾时仍会发出警告。
I understand what the warning is for, and how to turn off the line-ending flag, but how do I turn off the warning itself?
我了解警告的用途,以及如何关闭行结束标志,但如何关闭警告本身?
回答by Chronial
You can turn off the warning with
您可以关闭警告
git config --global core.safecrlf false
(This will only turn off the warning, not the function itself.)
(这只会关闭警告,而不是功能本身。)
回答by Adam Dymitruk
You should use core.autocrlf input
and core.eol input
. Or just don't let git change the line endings at all with autocrlf false
and get rid of highlighting of crlfs in diffs, etc with core.whitespace cr-at-eol
.
你应该使用core.autocrlf input
和core.eol input
。或者只是不要让 gitautocrlf false
用core.whitespace cr-at-eol
.
Hope this helps
希望这可以帮助
回答by Pat Notz
You're looking for the core.whitespace
option (see git config --help
for details).
您正在寻找该core.whitespace
选项(git config --help
有关详细信息,请参阅)。
You can set this option like so:
您可以像这样设置此选项:
$ git config core.whitespace cr-at-eol
回答by Julia Shestakova
I used this way:
我用这种方式:
Save your current files in Git, so that none of your work is lost.
git add . -u git commit -m "Saving files before refreshing line endings"
Remove every file from Git's index.
git rm --cached -r .
Rewrite the Git index to pick up all the new line endings.
git reset --hard
Add all your changed files back, and prepare them for a commit. This is your chance to inspect which files, if any, were unchanged.
git add . # It is perfectly safe to see a lot of messages here that read # "warning: CRLF will be replaced by LF in file."
Commit the changes to your repository.
git commit -m "Normalize all the line endings"
将您当前的文件保存在 Git 中,这样您的任何工作都不会丢失。
git add . -u git commit -m "Saving files before refreshing line endings"
从 Git 的索引中删除每个文件。
git rm --cached -r .
重写 Git 索引以获取所有新行结尾。
git reset --hard
重新添加所有更改的文件,并为提交做好准备。这是您检查哪些文件(如果有)未更改的机会。
git add . # It is perfectly safe to see a lot of messages here that read # "warning: CRLF will be replaced by LF in file."
将更改提交到您的存储库。
git commit -m "Normalize all the line endings"
回答by Jean-Michel Bernard
Funnily enough, I had applied both configs like explained here, and my .gitconfig file contained these 2 lines:
有趣的是,我已经应用了这里解释的两个配置,我的 .gitconfig 文件包含以下两行:
[core]
autocrlf = false
whitespace = cr-at-eol
Yet I got the warning. Now just to try I commented out both lines and the warning actually disappeared. No idea why I put them in the first place however...
然而我得到了警告。现在只是为了尝试,我注释掉了两行,警告实际上消失了。不知道为什么我把它们放在第一位......
回答by Park JongBum
Setting "core.safecrlf false" works. However, after I changed the value to 'true' The output changes from 'warning' to 'fatal' as shown below.
设置“core.safecrlf false”有效。但是,在我将值更改为 'true' 后,输出从 'warning' 变为 'fatal',如下所示。
$ git add -A
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory
$ git config --global core.safecrlf false
$ git reset
$ git config --global core.safecrlf true
$ git add -A
fatal: LF would be replaced by CRLF in .gitignore
$