Imagine a scenario in which you have used a rebase in your branch and lost it in n commits or reset --hard.
Now all commits have been lost or rebased, simply placed, they are no longer recognizable using their previous commit IDs.
If you would like to go back to the repo state before rebase or reset --hard, you can use git reflog.
Git internally maintains a state log of your HEAD and any changes that have been made to it.
git reflog
7b4ab0e HEAD@{0}: checkout: moving from 3-dummy to master
a256440 HEAD@{1}: commit (amend): Fixes Dummy Issue
d848c34 HEAD@{2}: commit: Fixes issue#3
09dca41 HEAD@{3}: commit: Issue 3 first cut
7b4ab0e HEAD@{4}: checkout: moving from master to 3-dummy
7b4ab0e HEAD@{5}: clone: from [email protected]:abishekk92/box.git
If you notice, all changes in the HEAD state are recorded. When we know which state we want to move the HEAD to,
git reset --hard HEAD@{x}
If you have changes and you can not do a forced restart for a given reflog, but you still want the commit changes to be lost.
git cherry-pick <commit-hash>