Windows git warning LF will be replaced by CRLF is that warning tail backward

0 votes

Env:

  • Windows 7

  • msysgit

When I git commit, it says:

warning: LF will be replaced by CRLF.

Is this warning tail backward?

I edit file in Windows, the end of line is CRLF, just like this pic:

enter image description here

And git changes it to LF for committing to repo.

So I think the correct warning is:

warning: CRLF will be replaced by LF.

Feb 16 in Others by Soham
• 9,330 points
866 views

1 answer to this question.

0 votes

 Depending on the editor you are using, a text file with LF wouldn't necessarily be saved with CRLF: recent editors can preserve eol style. But that git config setting insists on changing those...

Simply make sure that :

git config --global core.autocrlf false
 

That way, you avoid any automatic transformation, and can still specify them through a .gitattributes file and core.eol directives.


windows git "LF will be replaced by CRLF"

Is this warning tail backward?

No: you are on Windows, and the git config page does mention to use this setting if you want to have CRLF line endings in your working directory even though the repository does not have normalized line endings.

As described in "git replacing LF with CRLF", it should only occur on checkout (not commit), with core.autocrlf=true.
repo / \ crlf->lf lf->crlf / \  

That specific warning "LF will be replaced by CRLF" comes from convert.c#check_safe_crlf():

if (checksafe == SAFE_CRLF_WARN) warning("LF will be replaced by CRLF in %s. The file will have its original line endings in your working directory.", path); else /* i.e. SAFE_CRLF_FAIL */ die("LF would be replaced by CRLF in %s", path); It is called by convert.c#crlf_to_git(), itself called by convert.c#convert_to_git(), itself called by convert.c#renormalize_buffer() and that last renormalize_buffer() is only called by merge-recursive.c#blob_unchanged(). So I suspect this conversion happens on a git commit only if said commit is part of a merge process. When calling convert_to_git(), the checksafe parameter defines what should happen if the EOL conversion (CRLF --> LF --> CRLF) does not roundtrip cleanly. In addition, it also defines if line endings should be renormalized (CRLF --> LF) or kept as they are.

checksafe was an safe_crlf enum with these values:
SAFE_CRLF_FALSE: do nothing in case of EOL roundtrip errors SAFE_CRLF_FAIL: die in case of EOL roundtrip errors SAFE_CRLF_WARN: print a warning in case of EOL roundtrip errors SAFE_CRLF_RENORMALIZE: change CRLF to LF SAFE_CRLF_KEEP_CRLF: keep all line endings as they are

answered Feb 16 by Aditya
• 7,660 points

Related Questions In Others

0 votes
0 answers

LF will be replaced by CRLF in git - What is that and is it important?

I was trying to create a new ...READ MORE

May 16 in Others by Kichu
• 19,040 points
244 views
0 votes
0 answers
0 votes
0 answers
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
1,890 views
+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Squash my last X commits together using Git

You can do this relatively easily without ...READ MORE

answered Feb 16 in Others by Aditya
• 7,660 points
30 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP