Cancel "git checkout HEAD foo.c" in git scm

I made a mistake with my latest changes to HEAD by mistake.

git checkout HEAD foo.c 

this means that I lost all my changes that I wanted to commit ...

Is there a way to find these changes in the git cache or in some local history?

+7
source share
2 answers

if you didn’t hide the changes in the file while working (and then restored them), then you can do little with it.

if you added the file changes using git add (probably you have it because you were about to commit), then blob should already be in git db. you can use git fsck to search for dangling objects. look for blobs and check all of them - either using git show or git cat-file - (it takes time, I know ...), but if you're lucky, you will find the contents of your file. use git cat-file blob $hash_of_object > foo.c to restore the contents of your file

+7
source

If you didn’t do this (or hid it or added it to the index), git will not know about your local changes. So no.

+3
source

All Articles