Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get git autocrlf=true to work

Ok, so i have read all threads on this topic, and my understanding is the following:

if i set core.autocrlf = true in Windows, git should convert all my crlf line endings to LF when committing and pushing.

This is what i want, and i have my config set up as such. However, when i check in a text file with CRLF endings, i get the error messsage:

fatal: LF would be replaced by CRLF

I don't get it... shoudn't the opposite happen when i commit?

like image 207
Mathias Avatar asked Sep 06 '25 17:09

Mathias


1 Answers

The message is misleading, but makes sense:

  1. You check in your file, line ending normalization is done: CRLF is replaced with LF, LF is kept as LF.
  2. Later on, you check out the file in question. Now git will “undo” the line ending normalization: LF will be replaced with CRLF.

At the end of that process, all the LFs in your working dir have been replaced with CRLF. That is what git is warning you about.

Note: I would not recommend using core.autocrlf – it is an old setting that has been superseded. Use attributes instead. See here: https://stackoverflow.com/a/13154031/758345

like image 104
Chronial Avatar answered Sep 08 '25 21:09

Chronial