Line ending normalization doesn't work as expected
- From
- Robert Dailey <rcdailey.lists@gmail.com>
- Date
- Oct 3, 2017, 15:00 UTC
- Message-ID
- <CAHd499B5hM9ixnsnwWwB2uyDT10dRQpN473m5QjxH9raHtFXiw@mail.gmail.com>
I'm on Windows using Git for Windows v2.13.1. Following github's recommended process for fixing line endings after adding a `.gitattributes` file[1], I run the following:
$ rm .git/index && git reset
Once I run `git status`, I see that no files have changed. Note that I know for a fact in my repository, files were committed using CRLF line endings (the files in question are C# code files, and no .gitattributes was present at the time).
I also tried this:
$ git rm -r --cached . && git reset --hard
However, again `git status` shows no working copy modifications. The one thing that *did* work (and I tried this on accident actually) is:
$ git rm -r --cached . && git add .
This properly showed all files in my index with line ending modifications (I ran `git diff --cached -R` to be sure; the output shows `^M` at the end of each line in the diff in this case). Note that my global git config has `core.autocrlf` set to `false`, but I also tried the top 2 commands above with it set to `true` but it made no difference.
So my question is: Why do the top 2 commands not work, but the third one does? To me this all feels like magic / nondeterministic, so I'm hoping someone here knows what is going on and can explain the logic of it. Also if this is a git config issue, I'm not sure what it could be. Note my `.gitattributes` just has this in it:
* text=auto
Thanks in advance.
[1]: https://help.github.com/articles/dealing-with-line-endings/