Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I re-checkout all files in Git to convert from CRLF to LF?

Tags:

git

I have files checked out with CRLF. I changed git config --global core.autocrlf false. Git doesn't see any modifications. When I edit a file, Git thinks the whole file changed. How do I re-checkout and overwrite all the files with LF instead of CRLF, so the diff works as expected? I saw this but the answer referred to an invalid command. I saw this but it said "Git wants to commit files that you have not modified" which is not true. I tried

git pull --force
git checkout --force

However the files still have CRLF. So how do I convert all the files from CRLF to LF? I can edit each & every file in Notepad++ and use Edit > EOL Conversions > Unix (LF), which is what I've been doing on a file by file basis, but it's very tedious. There is probably an awk or sed script also, but I'm not familiar with them, and I'd prefer to only modify what is checked into Git, and not mess up .git/.


Also tried

git reset --hard origin/master

And the files are still with CRLF!


This is not a duplicate of the suggested duplicate because I don't want to commit anything. Only want to fetch a fresh copy from Git. Also, Git doesn't see any files as being modified.

like image 953
Chloe Avatar asked May 15 '18 15:05

Chloe


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?

#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. #Rewrite the Git index to pick up all the new line endings.

How do I change my Crlf?

At the bottom right of the screen in VS Code there is a little button that says “LF” or “CRLF”: Click that button and change it to your preference. Voila, the file you are editing now has the correct line breaks.


1 Answers

This seemed to work, but I'm not sure why. It looks very scary with lots of changes, but it ended up not changing anything. I got worried after the first line.

git rm --cached -r .
git reset
git checkout .

No commits necessary.

like image 138
Chloe Avatar answered Sep 28 '22 16:09

Chloe