Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

caching

I did checkout a file with my latest changes to HEAD by mistake..

git checkout HEAD foo.c

that means i lost all my changes that i wanted to commit...

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

like image 382
Mesut Avatar asked Feb 07 '11 10:02

Mesut


2 Answers

if you have not stashed changes to the file while working (and then restoring them) then there's little you can do about it.

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

like image 188
knittl Avatar answered Oct 17 '22 03:10

knittl


Unless you have committed it, (or stashed it or added it to index) git wouldn't know about your local changes. So, no.

like image 34
lprsd Avatar answered Oct 17 '22 01:10

lprsd