1

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?

srage
  • 990
  • 1
  • 9
  • 27
  • 1
    Sorry, not a direct answer, but I found configuring line endings via `.gitattributes` to be *massively* superior to trying to find and enforce the "correct" setting for `core.autocrlf`, because once it's set up it applies to **all** clones of that repository independent of any local configuration of the git client. Moving to that approach has basically eliminated all headache related to line endings. (And the subjective part: we standardize to LF line ending for everything except for file types that specifically need CRLF like .bat or .cmd). – Joachim Sauer Mar 09 '23 at 10:14

2 Answers2

1

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

srage
  • 990
  • 1
  • 9
  • 27
0

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • just curious: isn't there also a `git update-index` hocus pocus formula to rerun content through git filters ? – LeGEC Mar 14 '23 at 04:10
  • 1
    @LeGEC After re-reading [torek's post](https://stackoverflow.com/a/73579300/6309), not that I know of. – VonC Mar 14 '23 at 07:37
  • @VonC I tried this using git version 2.30.2 and it did not work. Here is the script I'm using to test: https://gist.github.com/skurhse/e6f0bd539cb43f7f14d66210856e0911 – srage Mar 15 '23 at 01:18
  • 1
    @srage Then I would use gitattributes directives: they are more precise and reliable. – VonC Mar 15 '23 at 12:25