Susheel Javadi Susheel Javadi - 3 months ago 29
Git Question

Recovering added file after doing git reset --hard HEAD^

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: Undoing a git reset --hard HEAD~1 but, that question assumes that the one has done a git commit.


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 --unreachable  HEAD

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

Please read git fsck manpage.