Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git auto convert file from CRLF to LF not working

Tags:

git

git-config

On our system, we used to be able to convert all CRLF to LF while committing file into git. Now this feature is gone.

Here is what I've done:

git config --global core.autocrlf false

After doing the above, I use the following command to check:

git config --list

The result is:

... 
core.autocrlf=input
...
core.autocrlf=false
...

It's very puzzling. While there's two entries of core.autocrlf, and the first one is core.autocrlf=input? If I unset core.autocrlf using:

git config --global --unset core.autocrlf

I still get one entry when I list git config:

core.autocrlf=input

Step 2: After I did git config --global core.autocrlf false, I add * text=auto into .gitattributes file.

But git still does not automatically convert line break for me.

like image 583
Xiaoyun Wu Avatar asked Apr 17 '15 15:04

Xiaoyun Wu


People also ask

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.

How do I fix Git line endings?

fix-git-line-endings # With the exception that we are forcing LF instead of converting to windows style. #Set LF as your line ending default. #Save your current files in Git, so that none of your work is lost. #Remove the index and force Git to rescan the working directory.

Should I use CRLF or LF?

Whereas Windows follows the original convention of a carriage return plus a line feed ( CRLF ) for line endings, operating systems like Linux and Mac use only the line feed ( LF ) character. The history of these two control characters dates back to the era of the typewriter.

What does Autocrlf input do?

core. autocrlf = input This means that Git will process all text files and make sure that CRLF is replaced with LF when writing that file to the object database.


1 Answers

Since git1.8.1rc1 :

"git config --get" used to diagnose presence of multiple definitions of the same variable in the same configuration file as an error, but it now applies the "last one wins" rule used by the internal configuration logic

So your second setting apply.

For more explaination on option for core.autoctrlf :

If you’re on a Windows machine, set it to true – this converts LF endings into CRLF when you check out code:

$ git config --global core.autocrlf true

You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input:

$ git config --global core.autocrlf input

If you’re a Windows programmer doing a Windows-only project, then you can turn off this functionality, recording the carriage returns in the repository by setting the config value to false:

$ git config --global core.autocrlf false

more explanation : http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#Formatting-and-Whitespace

like image 138
flafoux Avatar answered Nov 15 '22 09:11

flafoux