Can't seem to discard changes in Git Can't seem to discard changes in Git git git

Can't seem to discard changes in Git


This has been bothering me for a while, almost every repo I'd check out had changes that I couldn't discard. Long story short, I tried all of the above, nothing worked. This is what I did to get things back to normal (on a Mac):

Completely remove the autocrlf & safecrlf settings from ~/.gitconfigCompletely remove the autocrlf & safecrlf settings from your repo's local config ./.git/configgit rm --cached -r .git reset --hard


Here is my experience, set following variables in .git/config:

[core]    autocrlf = false    safecrlf = false    eol = crlf

then run $ git checkout HEAD ., and it works. but $ git checkout -- . not, strange!

* git version 1.9.3


What changes does git diff show on the file? On windows, I've seen issues with line-endings causing issues like this. In that case, look at what settings you have for git config core.autocrlf and git config core.safecrlf. There is some documentation for these settings here.

I would say, if you are using git svn for integration with subversion, then do make sure autocrlf is turned off. From what I can tell it is just broken in this configuration and it makes most of the tools think files have been changed, when you have done a checkout to revert any changes.

If you are seeing a problem where you do git checkout, and then git status shows the file is still modified, and git diff shows the file is modified on every line in the file, then this is the problem you are seeing.

core.autocrlf

If true, makes git convert CRLF at the end of lines in text files to LFwhen reading from the filesystem, andconvert in reverse when writing to thefilesystem. The variable can be set toinput, in which case the conversionhappens only while reading from thefilesystem but files are written outwith LF at the end of lines.Currently, which paths to consider"text" (i.e. be subjected to theautocrlf mechanism) is decided purelybased on the contents.

core.safecrlf

If true, makes git check if converting CRLF as controlled bycore.autocrlf is reversible. Git willverify if a command modifies a file inthe work tree either directly orindirectly. For example, committing afile followed by checking out the samefile should yield the original file inthe work tree. If this is not the casefor the current setting ofcore.autocrlf, git will reject thefile. The variable can be set to"warn", in which case git will onlywarn about an irreversible conversionbut continue the operation....