Restore lost commits in Git

So, you’ve called a git reset –hard on a wrong branch or did some other destructive action (perhaps a wrong rebase, amend etc.), and lost some important commit(s) in the repository.

Well, fortunately nothing is actually lost, and Git allows us to recover such detached commits. Even amended commits can be restored back to the previous state using the following technique.