使用Git时,当使用autocrlf=true
标志时,仍会在更改行尾时发出警告。
我理解警告的含义以及如何关闭行尾标志,但我该如何关闭警告本身?
使用Git时,当使用autocrlf=true
标志时,仍会在更改行尾时发出警告。
我理解警告的含义以及如何关闭行尾标志,但我该如何关闭警告本身?
git config --global core.safecrlf false
(这只会关闭警告,而不是功能本身。)
core.autocrlf input
和core.eol input
。或者完全不要让git改变行尾,使用autocrlf false
,并通过core.whitespace cr-at-eol
消除差异中的crlfs高亮显示。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 rm --cached -r . && git reset --hard
看起来可以解决问题,谢谢。 - Shanimal您正在寻找 core.whitespace
选项(有关详细信息,请参见 git config --help
)。
您可以这样设置此选项:
$ git config core.whitespace cr-at-eol
设置 "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
$
[core]
autocrlf = false
whitespace = cr-at-eol
然而我收到了警告。 现在只是为了尝试,我注释掉了这两行代码,结果这个警告竟然消失了。 不过我真的不知道当时为什么要加上这两行代码...
.git/config
中有其他设置,那些设置将会覆盖你的全局设置。 - CervEd