Recovering Deleted Commits

In this episode, we're going to recover some commits that we've lost through a “git reset”.

Transcript
Recovering Deleted Commits

In this episode, we're going to recover some commits that we've lost through a "git reset".

Here’s an example scenario: you might have rolled back your history with a reset command. But, as life goes, you might regret this shortly after - and wish you hadn’t lost those commits!

So, let’s quickly perform a reset that we can then undo.

And we can indeed undo even a reset! Git offers a tool called the “reflog” that is also available via Tower. In case it doesn’t show up in your sidebar, then make sure the Reflog is activated in Tower’s preferences.

You can think of the Reflog as a journal that keeps track of every movement of the HEAD pointer - when you’re doing a checkout, commit, reset, cherry-pick…

The reflog lists these actions in chronological order. Right at the top, there’s the reset that we just performed. So, in order to undo this action, we can simply return to the state before that action.

All we have to do is right-click the state we want to return to and choose to create a new branch on that commit.

And voila: we’ve successfully restored those lost commits!