With Git, how do I turn off the “LF will be replaced by CRLF” warning

∥☆過路亽.° 提交于 2019-12-17 21:39:11

问题


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?


回答1:


You can turn off the warning with

git config --global core.safecrlf false

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




回答2:


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




回答3:


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



回答4:


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/




回答5:


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



来源:https://stackoverflow.com/questions/6500880/with-git-how-do-i-turn-off-the-lf-will-be-replaced-by-crlf-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!