Reputation: 621
Trying to discard changes on server, and make it exactly the same as origin/master:
git fetch --all
git reset --hard origin/master
I've done this before on same repo without problems, but this time it fails with the following:
fatal: Could not reset index file to revision 'origin/master'
Have tried the following:
remove index and reset as suggested here:
rm .git/index
git reset
also suggested here that some process could have a lock on .git\index. That killing process and then executing git reset
could fix it, but not sure how to check if something has a lock on file remotely. Also seems that removing index file and reset would have had same effect.
Loosing my mind. Would really appreciate any help.
Upvotes: 49
Views: 99088
Reputation: 151
I had the same error message after renaming a branch and then stashing - there was some dangling ref. to one of my files.
error: unable to unlink old 'my_filename.ext': Invalid argument
fatal: Could not reset index file to revision 'HEAD'
I was able to unlink the old file with:
git restore <my_filename.ext>
Upvotes: 5
Reputation: 1633
Had the same issue, which quite crazy cause reset --hard
should always work, but it seems the working tree had a lot of differences to my target branch.
I had no time to dig this down, but found this by accident:
Run git gc
to do some garbage collection. It will remove unnecessary files and optimize the local repository (more info about git gc
can be found here).
Simply reset
and finally reset --hard
to desired branch.
$ git gc
$ git reset
$ git reset --hard <target_branch>
Upvotes: 66
Reputation: 39
I had the same problem and realized that I had run out of disk space...
Upvotes: 3
Reputation: 1610
Just wanted to note that this ended up being the source of my problem:
also suggested here that some process could have a lock on .git\index. That killing process and then executing git reset could fix it, but not sure how to check if something has a lock on file remotely. Also seems that removing index file and reset would have had same effect.
If you're running anything on local, like Jekyll, React, etc. that has a lock on the files in your project, then killing that process with Ctrl+C/Cmd+C will do the trick.
Upvotes: 5