使用 Git,如何关闭“LF 将被 CRLF 替换”选项警告

发布于 2024-11-17 11:16:52 字数 105 浏览 6 评论 0原文

在 Git 中,当使用 autocrlf = true 标志时,更改行结尾时仍会发出警告。

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

With Git, when using the autocrlf = true flag, a warning is still given when line-endings are changed.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

|煩躁 2024-11-24 11:16:53

您正在寻找 core.whitespace 选项(有关详细信息,请参阅 git config --help)。

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

$ git config core.whitespace cr-at-eol

You're looking for the core.whitespace option (see git config --help for details).

You can set this option like so:

$ git config core.whitespace cr-at-eol
乄_柒ぐ汐 2024-11-24 11:16:53

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

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

但我收到了警告。
现在,为了尝试,我注释掉了这两行,警告实际上消失了。
不知道为什么我把它们放在第一位,但是......

Funnily enough, I had applied both configs like explained here, and my .gitconfig file contained these 2 lines:

[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...

糖果控 2024-11-24 11:16:53

设置“core.safecrlf false”有效。但是,在我将值更改为“true”后,输出从“警告”更改为“致命”,如下所示。

$ 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

$

Setting "core.safecrlf false" works. However, after I changed the value to 'true' The output changes from 'warning' to 'fatal' as shown below.

$ 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

$
一个人的夜不怕黑 2024-11-24 11:16:52

您可以使用以下命令关闭警告

git config --global core.safecrlf false

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

You can turn off the warning with

git config --global core.safecrlf false

(This will only turn off the warning, not the function itself.)

夜雨飘雪 2024-11-24 11:16:52

您应该使用 core.autocrlf inputcore.eol input。或者只是不要让 git 使用 autocrlf false 根本改变行结尾,并使用 core.whitespace cr-at-eol 消除差异中 crlfs 的突出显示等。

希望这有帮助

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.

Hope this helps

傲娇萝莉攻 2024-11-24 11:16:52

我用的是这样的方式:

将当前文件保存在 Git 中,这样您的工作就不会丢失。

<前><代码>git add . -u
git commit -m“刷新行结尾之前保存文件”

从 Git 索引中删除每个文件。

git rm --cached -r 。

重写 Git 索引以获取所有新行结尾。

git reset --hard

将所有更改的文件添加回来,并准备提交。这
您有机会检查哪些文件(如果有)未更改。

<前><代码>git add .
# 在这里看到很多消息是完全安全的
# “警告:文件中的 CRLF 将被 LF 替换。”

将更改提交到您的存储库。

git commit -m "标准化所有行结尾"

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

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"

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文