Git warning: LF will be replaced by CRLF

Asked

Viewed 29,427 times

33

I created a file called tests.html inside a folder.

After typing:

git add tests.html 

Message appeared:

Warning: LF will be replaced by CRLF in testes.html
The file will have its original line endings in your Working directory.

The first time I added a file no message appeared, but now it appeared...

What does it mean LF and CRLF?

What this warning means or what is happening?

2 answers

42


Line terminator

  • LF => Line Feed (ASCII 10)
  • CRLF => Carriage Return + Line Feed (ASCII 13+10)

This is how the text lines of the file end. Either with just one character or with both. In general the first is preferred in one operating system (Linux for example) and the second preferred in another (Windows).

Line terminator is the way the end of each line of a text file is indicated. It needs some character to determine that the line is over. In general this character is not shown in the text in editors and listings but it is there in the file. Without it how would you know that the line has ended? We can say, very roughly, that this is the ENTER that is there.

Some editors have an option to display these characters in a special way.

inserir a descrição da imagem aqui

The ideal is to always maintain the same standard (some software may even have problems because of this).

How Git Handles It

If there is no consistency Git can convert for you.

This message is only letting you know that it made the conversion for you.

You can change this behavior with:

git config core.autocrlf true

but the most common is to leave as

git config core.autocrlf input

You probably saved the file with a line terminator that is not desirable. Or maybe the file came from somewhere else that has a different terminator.

  • What do you mean by line terminator @bigown?

  • See in the edition if improved.

  • 1

    Now it worked... I used git config core.autocrlf input and the warning stopped coming... Thank you so much!

  • Yes, quite a lot... ^_^

  • and as to the safecrlf and eol?

  • @Bernardoa.Dalcorno what you have?

  • @Maniero I saw a people commenting that safecrl=false would be better than autocrlf (I mean, will it change the files without worrying? ). And I didn’t quite understand the relationship of eol with these two reading the documentation

  • Can someone explain to me what this command does and why it solves the problem ? Command: git config core.autocrlf input input

Show 3 more comments

8

Come on.

What does LF and CRLF mean?

LF means Line Feed and CRLF means Carriage Return Line Feed. Both are different line breaking forms in the files. LF is adopted by Linux/Unix based systems and CRLF is adopted by Windows.

This kind of warning:

Warning: LF will be replaced by CRLF in testes.html

It’s okay common when in the same repository there are people working on the same file with Linux and others with Windows. As many editors do not respect the line break pattern adopted in the file, they end up overwriting the existing line break, generating this confusion.

Lucky for us, Git can handle this scenario by converting from one type of line break to another. In the above notice, Git means that you will lose the Unix LF line break after the commit (being replaced by Windows CRLF format). Git, in this case, does not expect you to use Unix LF format on Windows.

The Git flag that helps us control this is the core.autocrlf. It works thus:

core.autocrlf=true:      core.autocrlf=input:     core.autocrlf=false:

        repo                     repo                     repo
      ^      V                 ^      V                 ^      V
     /        \               /        \               /        \
crlf->lf    lf->crlf     crlf->lf       \             /          \      
   /            \           /            \           /            \

To general recommendation for Windows is leave this option as true.

git config --global core.autocrlf true

For summing up:

  • Use core.autocrlf = true whether you plan to use this project on Linux/Unix and Windows (not wanting to configure your editor to use Unix format)
  • Use core.autocrlf = false whether you plan to use the project only on Windows (or whether you have configured your editor to use the Unix line break format)
  • Not use core.autocrlf = input unless you have a good reason (example: you are using Unix utilities on Windows)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.