LF will be replaced by CRLF in git -the file will

2019-07-22 04:39发布

问题:

LF will be replaced by CRLF in git -the file will have its original line endings what does this mean?

回答1:

This usually happens when you are on Windows and either core.autocrlf is set to true, or the .gitattributes contains directives to perform line ending normalizations.

The way line ending normalization works (on a Windows machine) is that when you commit a file, git replaces every CRLF with a LF, and when you checkout a file, git replaces every LF with a CRLF. Normally this is all transparent to you, and all you ever see is CRLFs in your working directory. However, if you somehow create a file with just LFs in your working directory, here is what will happen:

  1. When committing, git will "convert" the LFs to LFs, i.e. do nothing
  2. When checking out, git will convert the LFs to CRLFs

The upshot is, you end up creating a file with just LFs, but from then on you always see CRLFs in it. That is what git is warning you about.

Assuming that it is a text file we are talking about, you can go ahead and ignore this warning. However, if it is a binary file, it means that git is going to attempt to do line normalizations on it, which will corrupt the file. In that case you need to check your .gitattributes file and see why this is happening.



标签: git gitlab