All fixes

Help, I lost commits after git reset --hard

They are not gone. The reflog remembers every place HEAD has been, so you can jump right back.

What Git says~/my-app
git reset --hard HEAD~2
HEAD is now at c4fc956 Initial commit

The fix

  1. git reflog

    Lists every place HEAD has been, newest first. Find the line just below “reset: moving to HEAD~2” and copy its hash.

  2. git reset --hard 3fc4661

    Puts your branch back there. HEAD@{1} works instead of the hash if you have done nothing since the reset.

    Discards uncommitted changes

3fc4661 is an example. Replace it with your own.

What happens to your historygit reset --hard 3fc4661
BeforeABCHEADmain
AfterABCHEADmain

Why this works

A commit is only really deleted when nothing points to it anymore and Git cleans up, which takes weeks. Until then the reflog, Git's diary of where HEAD has been, still lists it. Find the moment before the reset and put your branch back there. Right after the bad reset, git reset --hard ORIG_HEAD gets you there too. Uncommitted changes that reset --hard threw away never made it into a commit, so the reflog cannot bring those back.