Recovering added/staged file after doing git reset --hard HEAD^?

Susheel Javadi picture Susheel Javadi · Jul 10, 2009 · Viewed 53.2k times · Source

I added a new file F1 and made changes to another file F2 but then did a "git reset --hard HEAD^" and I have lost all the changes to the files.

Is there some way, I can get them back?

I did look at a related question here: How can I undo git reset --hard HEAD~1? but, that question assumes that the one has done a git commit.

Answer

Jakub Narębski picture Jakub Narębski · Jul 10, 2009

You can (with some work) recover state of file at the last "git add <file>". You can use

$ git fsck --cache --no-reflogs --lost-found --dangling HEAD

and then examine files in '.git/lost-found/other' directory.

Please read git fsck manpage.