I have a repo that has two files that supposedly I changed locally.
So I'm stuck with this:
$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: dir1/foo.aspx
# modified: dir2/foo.aspx
#
no changes added to commit (use "git add" and/or "git commit -a")
Doing git diff
says that the entire file contents have changed, even though from eyeballing it that seems untrue (there seem to be common line ranges that diff seems to be failing to see).
Interestingly I don't remember changing these files locally. This repo is used with one remote repo (private, at GitHub.com, FWIW).
No matter what I've tried, I can't discard these local changes. I have tried all of:
$ git checkout -- .
$ git checkout -f
$ git checkout -- dir1/checkout_receipt.aspx
$ git reset --hard HEAD
$ git stash save --keep-index && git stash drop
$ git checkout-index -a -f
In other words I've tried everything described in How do I discard unstaged changes in Git? plus more. But the 2 files remain stuck as "changed but not committed".
What the heck would cause two files to be stuck like this and seemingly "un-revert-table"??
P.S. In the list above showing commands I'd already tried, I mistakenly wrote git revert
when I meant git checkout
. I'm sorry and thank you to those of you who answered that I should try checkout
. I edited the question to correct it. I definitely did already try checkout
.
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