16

I have already read the Git documentation discussed in this answer (LF will be replaced by CRLF in git - What is that and is it important?) but I don't understand what it means for my situation.

I have LF files which were introduced by a tool into my git checkout on Windows. When I tried to commit them, I got the warning warning: LF will be replaced by CRLF in [file].

git config core.autocrlf is true on this machine. I committed anyway. The line endings on Windows are still LF. Then I checked out the file on a Linux machine where git config core.autocrlf doesn't appear to be set. I inspected the line endings there, and they were also LF.

So what I don't understand is, WHERE is it saying that LF will be replaced by CRLF? Does it mean, next time I pull a change to the file (which is committed by somebody from another machine) the line endings will be converted?

Also - what line endings does Git use in its internal repo?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Stephen
  • 8,508
  • 12
  • 56
  • 96
  • The first answer in the dupe linked by the question you liked to contains the answer to your question: https://stackoverflow.com/a/1967986/87698. In a nutshell: git stores them as LF, but during **checkout on a Windows machine** all LFs will be converted to CRLFs. – Heinzi Mar 16 '18 at 15:10
  • You probably haven't tried the failure mode yet. Staying in Windows, check it in, delete the original, check it back out. That ought to produce CRLFs now. – Hans Passant Mar 16 '18 at 15:34

1 Answers1

13

I guess you'd say that internally git prefers LF. To say it "uses LF internally" isn't quite accurate, because you can configure it not to. (For example, if everyone on your team uses Windows so you all turn eol normalization off, then git will have the CRLF eol markers.)

What the warning is saying is, you're checking this in with linefeed normalization on, but it already has LF. If you check it back out with autocrlf in effect, you'll get CRLF endings. BUT since you have a local copy in your work tree, it will stay as it is.

So "where" would typically be any new repo using autocrlf=true ; or any colleague's repo if checking out from git creates the file for them locally

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52