Get back a commit after reset --hard
I used reset --hard and lost a commit I needed.
The problem
I used reset --hard and lost a commit I needed.
How the practice repository looked before
## main
de1ce31 Add notes
The fix
de1ce31 HEAD@{0}: reset: moving to HEAD~1
7c26407 HEAD@{1}: commit: Add line two
de1ce31 HEAD@{2}: commit (initial): Add notesHEAD is now at 7c26407 Add line two
Check the result
7c26407 Add line two de1ce31 Add notes
Why this works
The reflog is a private diary of where HEAD has been. The first line is the reset you just did, so HEAD@{1} is where you were before it. Resetting to it brings the commit back.
If this is not quite your case
If HEAD@{1} is not the one you need, read the reflog list and use the hash printed at the start of the right line instead: git reset --hard <hash>. To be careful, first make a branch there with git branch rescue <hash> and look at it before you move your branch.
Be careful: The reflog is local to your copy of the repository, and old entries are removed after some weeks (90 days for entries that are still reachable, 30 days for others, by default).
This is an independent guide. It is not connected with the Git project, GitHub, GitLab or any company named here. Every command below was run on 14 November 2026 with the real program (git version 2.56.0.windows.4) in a new empty practice repository; the output shown is what it printed. Facts about options were read in the official Git documentation on 14 November 2026.