Chloe
Chloe

Reputation: 26264

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

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.

Upvotes: 16

Views: 4063

Answers (2)

Chloe
Chloe

Reputation: 26264

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 --hard
git checkout .

No commits necessary.

Upvotes: 22

elixon
elixon

Reputation: 1292

git add --renormalize . and then committing all changed files did it for me.

As per man git add it specifically mentions to run that after core.autocrlf change.

--renormalize

Apply the "clean" process freshly to all tracked files to forcibly add them again to the index. This is useful after changing core.autocrlf configuration or the text attribute in order to correct files added with wrong CRLF/LF line endings. This option implies -u.

Upvotes: 2

Related Questions