188

在 Git 中,当使用autocrlf = true标志时,当行尾改变时仍然会给出警告。

我了解警告的用途,以及如何关闭行尾标志,但如何关闭警告本身?

4

6 回答 6

338

您可以关闭警告

git config --global core.safecrlf false

(这只会关闭警告,而不是功能本身。)

于 2013-02-01T06:26:24.127 回答
8

您应该使用core.autocrlf inputcore.eol input。或者根本不要让 gitautocrlf falsecore.whitespace cr-at-eol.

希望这可以帮助

于 2011-06-28T04:46:27.283 回答
3

我用这种方式:

将您当前的文件保存在 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"

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

于 2015-07-31T13:53:34.403 回答
0

您正在寻找该core.whitespace选项(详情请参阅git config --help)。

您可以像这样设置此选项:

$ git config core.whitespace cr-at-eol
于 2011-06-28T02:21:51.947 回答
0

有趣的是,我已经应用了这里解释的两个配置,我的 .gitconfig 文件包含以下两行:

[core]
       autocrlf = false
       whitespace = cr-at-eol

然而我得到了警告。现在只是为了尝试,我注释掉了这两行,警告实际上消失了。不知道为什么我把它们放在首位......

于 2019-09-19T14:05:17.417 回答
0

设置“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

$
于 2020-01-24T22:32:06.137 回答