git checkout -- <files> doesn't discard changes?

Viewed 24066

I have changes in my working directory that I'm trying to discard (reset to the current indexed version of the files), however, git checkout -- <file> will not discard the changes. I've attempted to manually remove the files (rm -r files) then run git checkout -- ., which displays the files as modified again.

$ git checkout -- .
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   files/Hulk.png
#   modified:   files/Hulk_2.png
#
no changes added to commit (use "git add" and/or "git commit -a")

Running git diff shows the files are modified...

diff --git a/files/Hulk.png b/files/Hulk.png
index 1c256cb..1d37fe0 100644
Binary files a/files/Hulk.png and b/files/Hulk.png differ
diff --git a/files/Hulk_2.png b/files/Hulk_2.png
index 1c256cb..0717199 100644
Binary files a/files/Hulk_2.png and b/files/Hulk_2.png differ

NOTE: Some people have said to run git checkout ., however this will achieve the same result as git checkout -- .. The -- is just a notation used in the git checkout command to differentiate treeish/commit points from files/paths.

OS: OSX 10.6 Git: 1.7.10.2

11 Answers

What helped in my case: (also improving vinboxx's answer)

I had got configured .gitattributes in a following way:

* text eol=crlf

(I wanted -X renormalize to automatically use proper format after merge)

After temporarily commenting that line along with setting git config core.autocrlf false. Everything went back to normal.

Related