Reset line endings in the working directory when *enabling* core.autocrlf

313 views Asked by At

Regarding core.autocrlf and working directory line-endings, I am seeing some strange, asymmetrical behavior when checking out files from the index.

When disabling auto-crlf, the following works as expected:

git config core.autocrlf # true
git config core.eol # crlf
git clone <repo_url>
cd <repo>
git config core.autocrlf false
git checkout . # Updated N paths from the index.

However, the inverse is not true. The following does not reset line-endings.

git config core.autocrlf # false
git config core.eol # crlf
git clone <repo_url>
cd <repo>
git config core.autocrlf true
git checkout . # Updated 0 paths from the index

How can I reset working directory line endings in the enable case? Is there a reason for this asymmetry that I'm not seeing, or is this a bug?

2

There are 2 answers

0
Skurhse Rage On BEST ANSWER

For the enable-case, you must execute git reset --hard, as opposed to the disable-case, where you can just run git checkout .

4
VonC On

How can I reset working directory line endings in the enable case?

As I mentioned in "Git: how to renormalize line endings in all files in all revisions?", since Git 2.16 (Q1 2018), you would use git add --renormalize . (instead of git rm --cached -rf .; git add .)

I would recommend using .gitattributes directives only (as in here), and keep core.autocrlf to false, as I have always recommended.