Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Unable to discard changes due to line endings?

Tags:

git

windows

"Out of the blue" I've started having this issue with a git repository that I have hosted on GitHub.

Whenever I pull a remote branch to my computer (even on the first clone of the repository) an arbitrary (?) set of files appear as "Changes not staged for commit". I am running on Windows 8.1 and using SourceTree alongside Git Bash as git clients.

An examination of the changes in these files shows that nothing has changed in them, except, maybe, the line endings. I don't know how to view the line endings when diffing so can't be sure.

When I try to "discard" these changes, it simply doesn't work. git reset --hard simply has no effect and the changes remain in place.

Why is this happening? How can I make it go away? :)

PS - When I run git config -l I see core.autocrlf=true appear 3 times in the list.

PPS - I have a .gitattributes file in the root of the repository. Deleting it does not have any effect on the above symptoms. It was first added a few days ago. It's all commented out except for * text=auto in the beginning of the file.

UPDATE:

I've found the minimum steps to reproduce my issue:

  1. I open a file in a text-editor, add a single space somewhere and save it.
  2. The file appears under "Changes not staged for commit" (obviously).
  3. I remove the single space from the file and save it.
  4. The file remains under "Changes not staged for commit" even though both SourceTree's diff and Kdiff3 show that the file is binary equal to its previous version.

Please note that the file in this example had CRLF line endings before I edited it and after I edited it - I don't understand why git insists on marking the file as changed.

UPDATE 2:

Running git diff --raw MyProject/app.config where MyProject.app/config is one of the files marked as changed gives:

:100644 100644 b960510... 0000000... M MyProject/app.config

The fact that the second SHA1 is all zeroes looks like a clue to me - but I don't know what it means.

like image 210
urig Avatar asked Sep 27 '22 05:09

urig


1 Answers

UPDATE 3: I was able to resolve my issue by removing the .gitattributes file from the root of my repository.

The most likely suspect for having added this file into the repo in the first place is Visual Studio 2013 are per this Microsoft Connect issue.

I still don't understand why having this file (with this core.autocrlf=true in it) caused the behavior that I observed. If anyone has a good explanation, please post it as an answer and I will accept it.

like image 50
urig Avatar answered Oct 06 '22 00:10

urig