在 Git 中,当使用autocrlf = true
标志时,当行尾改变时仍然会给出警告。
我了解警告的用途,以及如何关闭行尾标志,但如何关闭警告本身?
在 Git 中,当使用autocrlf = true
标志时,当行尾改变时仍然会给出警告。
我了解警告的用途,以及如何关闭行尾标志,但如何关闭警告本身?
您可以关闭警告
git config --global core.safecrlf false
(这只会关闭警告,而不是功能本身。)
您应该使用core.autocrlf input
和core.eol input
。或者根本不要让 gitautocrlf false
用core.whitespace cr-at-eol
.
希望这可以帮助
我用这种方式:
将您当前的文件保存在 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"
您正在寻找该core.whitespace
选项(详情请参阅git config --help
)。
您可以像这样设置此选项:
$ git config core.whitespace cr-at-eol
有趣的是,我已经应用了这里解释的两个配置,我的 .gitconfig 文件包含以下两行:
[core]
autocrlf = false
whitespace = cr-at-eol
然而我得到了警告。现在只是为了尝试,我注释掉了这两行,警告实际上消失了。不知道为什么我把它们放在首位......
设置“core.safecrlf false”有效。但是,在我将值更改为“真”后,输出从“警告”变为“致命”,如下所示。
$ 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
$