206

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?

LightCC
  • 9,804
  • 5
  • 52
  • 92
sent-hil
  • 18,635
  • 16
  • 56
  • 74
  • 5
    All the answers here are obsolete — after git introduced gitattributes. Safecrlf is your friend autocrlf is not! Please see [my answer](https://stackoverflow.com/a/59644154/3700414) – Rusi Jan 27 '20 at 05:59

6 Answers6

362

You can turn off the warning with

git config --global core.safecrlf false

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

Chronial
  • 66,706
  • 14
  • 93
  • 99
  • 2
    will turning off the warning prevent git from replacing lf by crlf? @chronial – aidonsnous Sep 29 '16 at 11:05
  • 11
    @aidonsnous From [git docs](https://git-scm.com/docs/gitattributes/1.7.3.3): 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. – Daynil Jan 21 '18 at 20:09
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

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • Usually, you want that your BAT scripts ends and be commited with CRLF, and your SH script with LF. – Sandburg Sep 13 '19 at 16:19
3

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/

Julia Shestakova
  • 869
  • 9
  • 16
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...

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

$
Park JongBum
  • 1,245
  • 1
  • 16
  • 27
  • In recent git better to use gitattributes than autocrlf. See [my answer](https://stackoverflow.com/a/59644154/3700414). All answers (on this q) are old and obsolete – Rusi Jan 29 '20 at 11:51
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
random
  • 9,774
  • 10
  • 66
  • 83
Pat Notz
  • 208,672
  • 30
  • 90
  • 92