I’m using git on ubuntu with autocrlf set to true. My editor is configured to use LF as end-of-line character. After I edited a file and did
git add .
I got :
warning: LF will be replaced by CRLF in file1.txt. (1)
The file will have its original line endings in your working directory. (2)
As to (1), why git would want to convert my LF in my file into CRLF? Should it work exactly the way around that only when your file contains CRLF and only then git will try to convert CRLF to LF?
As to (2), does that mean the file I’m looking at will still go with only LF but the snapshot in git’s staging area is converted?
By looking at the warning message, I am guessing your configuration is the following:
core.eolset tonative(default in git 1.7.2 and above) or have explicitly set core.eol tocrlfinputThese
git attributes,core.autocrlfandcore.eollet you configure what you want for line endings and their possible values and what they mean is captured in the git man page and this stackoverflow answerAnd the answer to both (1) and (2), your questions is, “Because you configured it so”
What you should do depends on what platform you are on, and what other platform you would access git from. It is recommended to let git store only
LFas the end of line, as the blob hash generated would change otherwise and git would complain of “changed lines” even when thee change may be only of the line end characters.Since you are on Ubuntu, you want to set
core.eoltolfandcore.autocrlftoinputso that git does not convert LF to CRLF in your working tree.