Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: How do I get rid of "warning: CRLF will be replaced by LF" without disabling safecrlf?

Tags:

git

I'm new to git, and I've read a lot about line endings and how git treats them. I'm on Windows by the way. I have made a .gitattributes file and set for example *.txt to text. When I commit a .txt file, I get the warning:

warning: CRLF will be replaced by LF in whatever.txt

But I know that. I don't need that warning. Replacing line endings in text files is what I want.

Now, setting safecrlf to false makes the warning disappear, but the manual for safecrlf reads:

If true, makes git check if converting CRLF is reversible when end-of-line conversion is active. Git will verify if a command modifies a file in the work tree either directly or indirectly. For example, committing a file followed by checking out the same file should yield the original file in the work tree. If this is not the case for the current setting of core.autocrlf, git will reject the file.

From that, safecrlf seems like a good idea to have. However, I don't understand why setting safecrlf to true gives me warnings about my text files; it seems to me that those are different issues -- the warning on text files and the checking if reversible. Indeed, git does not reject my file.

Can I get rid of the warnings for text files, and still have safecrlf set? Or am I misunderstanding something?

like image 730
oskarkv Avatar asked Jun 01 '13 14:06

oskarkv


People also ask

How do you remove warning LF will be replaced by CRLF?

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.

How do I change from CRLF to LF in git?

text eol=crlf Git will always convert line endings to CRLF on checkout. You should use this for files that must keep CRLF endings, even on OSX or Linux. text eol=lf Git will always convert line endings to LF on checkout. You should use this for files that must keep LF endings, even on Windows.

What does LF will be replaced by CRLF mean?

In Unix systems the end of a line is represented with a line feed (LF). In windows a line is represented with a carriage return (CR) and a line feed (LF) thus (CRLF). when you get code from git that was uploaded from a unix system they will only have an LF.

Does git change line endings?

However, it does not modify line endings in your working tree. This is essentially the same as setting core. autocrlf=input in your Git settings. More specifically, the text=auto option tells Git to only normalize line endings to LF for text files while leaving binary files (images, fonts, etc.)


2 Answers

As far as I can tell, setting core.safecrlf to false is the only way to turn off that warning.

safecrlf is generally not necessary if your attributes are set correctly. The point of safecrlf is to prevent normalization in a file that is supposed to have mixed (or non-LF) line endings in the repository. It's really only useful in combination with core.autocrlf (to make sure that its automatic guesses can't destroy anything), and if you're setting your own attributes via .gitattributes it should be okay to turn all that off.

like image 123
Jan Krüger Avatar answered Sep 18 '22 17:09

Jan Krüger


In your .gitattributes you can:

# normalize text files to use lf text eol=lf  # except these which we want crlf *.txt eol=crlf 
like image 34
Ian Mariano Avatar answered Sep 18 '22 17:09

Ian Mariano