Imagine a scenario where you’ve used a rebase on your branch and lost it in n commits or reset it --hard.
Now all commits have been lost or rebased, simply placed, they are no longer recognizable using their previous commit Ids.
If you’d like to revert to the state of the Repo before rebasing or resetting --hard, you can use git reflog.
Git internally maintains a status log of your HEAD and all 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 HEAD state are recorded. When we know what state we want to move HEAD to,
git reset --hard HEAD@{x}
If you have changes and can’t perform a forced reboot for a particular reflog, but still want the commit changes lost.
git cherry-pick <commit-hash>
Note: And also git cleans your blob as soon as it reaches 5,000 objects, so it wouldn’t be possible to reset to a very old state, unless you’ve set up git to do it.
Possible duplicate. <br> https://answall.com/questions/204286/como-recuperar-umbra%C3%A7o-deleted-no-git =D
– K4L1