With Git, how do I turn off the "LF will be replaced by CRLF" warning
Asked Answered
A

6

210

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?

Ambroid answered 28/6, 2011 at 2:16 Comment(1)
All the answers here are obsolete — after git introduced gitattributes. Safecrlf is your friend autocrlf is not! Please see my answerRadiopaque
S
366

You can turn off the warning with

git config --global core.safecrlf false

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

Scabbard answered 1/2, 2013 at 6:26 Comment(2)
will turning off the warning prevent git from replacing lf by crlf? @chronialAr
@Ar From git docs: If core.safecrlf is set to "true" or "warn", git verifies if the conversion is reversible for the current setting of core.autocrlf. For "true", git rejects irreversible conversions; for "warn", git only prints a warning but accepts an irreversible conversion. If you do not need to reject irreversible conversions, setting core.safecrlf to false suppresses the warning, but still auto converts.Greenaway
L
9

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

Legaspi answered 28/6, 2011 at 4:46 Comment(1)
Usually, you want that your BAT scripts ends and be commited with CRLF, and your SH script with LF.Danseuse
S
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/

Squishy answered 31/7, 2015 at 13:53 Comment(2)
I believe the OP was trying to avoid seeing those warnings anymore. Not normalize all of the line endings.Jump
git rm --cached -r . && git reset --hard seems to do the trick, thanksHurricane
H
0

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
Hagi answered 28/6, 2011 at 2:21 Comment(0)
E
0

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

Etruscan answered 19/9, 2019 at 14:5 Comment(3)
Did you have different settings for your repository?Haemin
Sorry for the late reply... I don't have my config file anymore but I use a similar one I think now and apart from these 2 lines, there's nothing related.Etruscan
Because if there are other settings in yout .git/config that would override your global onesHaemin
B
0

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

$
Besom answered 24/1, 2020 at 22:32 Comment(1)
In recent git better to use gitattributes than autocrlf. See my answer. All answers (on this q) are old and obsoleteRadiopaque

© 2022 - 2024 — McMap. All rights reserved.