2

I understand that Windows uses CRLF and that it's good practice to let Git change line endings to LF before committing and back to CRLF when checking out. For that reason, I have core.autocrlf set to true. However, contrary to what other threads say (e.g., this), I am still getting this warning:

warning: LF will be replaced by CRLF in [FILE_NAME]. The file will have its original line endings in your working directory.

Firstly, I thought setting core.autocrlf to true was supposed to stop these warnings. Secondly, isn't Git supposed to convert LF to CRLF when committing, not the other way around?

Interestingly, I just committed many files and got this warning for only two of them (a .csproj and a .cs).

P.S. I am using Git Bash on Windows.

lfk
  • 2,423
  • 6
  • 29
  • 46
  • Does [Customizing Git — Git Configuration](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration) and the section on `core.whitespace` immediately after the section on `core.autocrlf` provide any insight or help? How did you check that you have `core.autocrlf` set correctly? – Jonathan Leffler May 28 '17 at 06:24
  • I ran `git config core.autocrlf` and it printed `true`. – lfk May 29 '17 at 07:03

1 Answers1

3

that it's good practice to let Git change line endings to LF before committing and back to CRLF when checking out.

It is, but not with core.autocrlf.
You should always set core.autocrlf to false, as it would try and convert eol (end of line) for all files (including non-text file)

If you have files that need conversion, use an eol directive in a .gitattributes file.
Make sure to use the latest Git for Windows though: there was a bug in Git 2.10.

That being said, if you still want to use core.autocrlf, see "Make Git “LF will be replaced by CRLF” warnings go away": you can remove your index and checkout again.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    Still, why is it replacing LF with CRLF when adding to index? I thought it was supposed to be the opposite. – lfk May 29 '17 at 07:05
  • @Farshid Not sure: I know of https://stackoverflow.com/a/14039909/6309. What Git version are you using? the last one 2.13? (https://github.com/git-for-windows/git/releases/) What command are you doing to trigger that warning message? – VonC May 29 '17 at 07:21
  • @Farshid Do you have any .gitattributes in your repo, as seen in https://github.com/git/git/commit/15c96723457cfa1be6cdbd74e3131ecf13cd9790? That would explain the message if an eol directove were to force the eol to LF. – VonC May 29 '17 at 11:58
  • I have `* text=auto` in .gitattributes – lfk May 30 '17 at 14:01
  • I'm using 2.11.1. I need to update it. The command is `git add`, or `git commit -a`, which runs `add` itself. – lfk May 30 '17 at 14:03
  • @Farshid The warning might come from the .gitattributes directive. Yes, can you try and see with Git 2.13 first? – VonC May 30 '17 at 14:05