A reset that moved a branch, a completed rebase, commit --amend, or an accidental branch move does not necessarily mean the previous commit is gone. Git records previous values of HEAD and other refs in their reflogs. Before trying random fixes, inspect that history.
Start with:
git reflog
Look for the entry before the mistake. The default output keeps the numbered HEAD@{...} selectors visible, which makes the next commands easy to copy. Inspect the candidate before changing anything:
git show HEAD@{3}
The safest recovery step is usually to create a new branch at the old position:
git branch recovered-work HEAD@{3}
Now the commit is reachable through a stable branch ref, and you can compare, cherry-pick, merge, or reset deliberately.
Avoid reaching for reset --hard first. It can be the right command when you know exactly where the branch should point, but it discards staged and unstaged changes to tracked files and may overwrite untracked paths.
Creating a recovery branch protects the selected commit. It does not snapshot your current index or working tree. Check git status and preserve any uncommitted changes separately before running a hard reset.
If the useful entry is easier to identify by object ID, use the abbreviated object ID from the output when it is unambiguous:
git branch recovered-work 4f8c2ab
If you want the full object ID first, ask Git for it:
git rev-parse HEAD@{3}
If timestamps help while you are scanning, use git reflog --date=local, but copy the object ID from that output instead of relying on a numbered selector. With a date format enabled, Git shows entries such as HEAD@{Mon Jul 6 14:27:00 2026}.
git reflog --all can help when you do not know which ref recorded the movement, or when a branch was moved without being checked out.
The important caveat: reflogs are local. They are not a shared backup. Reflog entries can expire, often as part of Git maintenance. Once no ref or reflog entry retains an unreachable commit, its objects may eventually be pruned.
Use this when you rewrote local history and need to recover a recent commit. Reflog inspection and local recovery are safe, but coordinate carefully before force-pushing rewritten history to a branch other people use.