Recover commits with git reflog
The reflog records where local references such as HEAD and branches pointed recently. It can help recover commits after a reset, rebase, or local branch deletion.
Find the previous position
Look for the commit ID and description from before the mistake. Inspect it before recovering:
Create a recovery branch
A recovery branch gives the commit a name so it is not lost while you investigate.
Local record only
Reflog entries are local and expire. They are not available on a remote just because the commit was once pushed there.
Recover a deleted branch
If a local branch was deleted, locate its last commit in the reflog and recreate it:
Do not run cleanup commands until important commits have been recovered and verified.