Git: How to revert 2 files that are stubbornly stuck at "Changed but not committed"?

Solution 1:

I spent hours trying to solve a similar issue - a remote branch that I had checked out, which stubbornly showed four files as 'Changed but not updated', even when deleting all files and running git checkout -f again (or other variations from this post)!

These four files were necessary, but certainly hadn't been modified by me. My final solution - persuade Git that they had not been changed. The following works for all checked out files, showing 'modified' status - make sure you have already committed/stashed any that have really been modified!:

git ls-files -m | xargs -i git update-index --assume-unchanged "{}"

On Mac OSX, however xargs operates a little bit different (thx Daniel for the comment):

git ls-files -m | xargs -I {} git update-index --assume-unchanged {}

I've added this as a placeholder for myself for next time, but I hope it helps someone else too.

-Al

Solution 2:

What are the line endings in the files? I'm betting they're CRLF. If they are, check out this guide: http://help.github.com/line-endings/

In short, you need to make sure git is set to convert the line endings to LF on commit, and then commit those files. Files in the repo should always be LF, files checked out should be the OS's native, assuming you set git correctly.

Solution 3:

this is how I fixed the same problem in my case: open .gitattributes change:

* text=auto

to:

#* text=auto

save and close , then revert or reset, thanks to @Simon East for the hint

Solution 4:

Another possibility is that the difference (that's preventing your from reverting these files with a checkout command) is one of file mode. This is what happened to me. On my version of git you can discover this by using

git diff dir1/foo.aspx

And it will show you file mode changes. It still won't let you revert them, though. For that use either

git config core.filemode false

or change your git .config in your text editor by adding

[core]

filemode = false

After you do this, you can use

git reset HEAD dir1/foo.aspx

and the file should disappear.

(I got all of this from the answer to How do I make git ignore mode changes (chmod)?)