Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Git "LF will be replaced by CRLF" warnings go away

Tags:

git

I have setup Git so it doesn't commit inconsistent line endings. The problem with that is a whole pile of files appear modified even though they are not. What do I type to make these files have the line endings fixed on the local side?

# git checkout dev M   src/au/policy/dao/EmailQueue.java M   src/au/policy/dao/EmailQueueFactory.java M   src/au/policy/dao/PolicyPublisher.java Already on 'dev'  # git diff warning: LF will be replaced by CRLF in src/au/policy/dao/EmailQueue.java warning: LF will be replaced by CRLF in src/au/policy/dao/EmailQueueFactory.java warning: LF will be replaced by CRLF in src/au/policy/dao/PolicyPublisher.java 

This is what I added to my git config file which seems to do what I intended aside from this issue:

autocrlf = true 
like image 230
corydoras Avatar asked Oct 21 '09 01:10

corydoras


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.

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.

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.

Should I use LF or CRLF?

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.


2 Answers

This might happen if you change core.autocrlf config variable (if I understand your problem correctly).

If you are at clean state, i.e. just after commit, and you don't have uncomitted changes, forced re-checkout and removing index should do the trick:

The below command git reset --hard HEAD will make your current branch to point to the latest commit and all uncommitted code will be lost. Make sure to commit the code or take the backup

$ rm .git/index $ git reset --hard HEAD 

That, I think, would sync both working area files, and the index (staging area) to follow crlf settings.

like image 82
Jakub Narębski Avatar answered Oct 07 '22 16:10

Jakub Narębski


I had this problem when creating new Xcode project. My solution for this problem:

In terminal write

$: git config --global --edit 

Then in git config file change safecrlf to false. My settings:

[core]     autocrlf = input     safecrlf = false 

I know git have cmd line tools for this but they don't work for me. And then Xcode create git repos without any problem.

like image 25
Sonique Avatar answered Oct 07 '22 17:10

Sonique