Recover Deleted GIT Commits

Have you ever force-deleted a branch from GIT by accident? Of course, it confirms with you first, but chances are you were deleting other branches, too, and this one got in the way. Luckily for you, it’s possible to retrieve these missing commits.

If you’re using GIT Extensions, you can use the GUI to accomplish the work. To do so, click on Repository > Git maintenance > Recover Lost Objects…

Recover Deleted GIT Commits

Recover lost objects is a feature of Git that will locate dangling commits – commits without a reflog. You can also accomplish the below by running git fsck utility with the –full option.

Ordinarily GIT will remove these lost objects every two weeks through garbage collection. This means you have a limited window of time to recover anything you’ve lost. A helpful dialog will show while Git combs your local repository for dangling commits:

Recover Deleted GIT Commits

Once completed, you’ll see about two weeks-worth of sortable dangling commits:

Recover Deleted GIT Commits

You can check any number of commits that you want to recover. I’ve selected just one from the list. When you’re sure you’ve found the one you want to recover, click on [Recover selected objects].

You’re not done yet, though! You still have to find a place to put the now recovered commit. Close the dialog to see the commit you’ve recovered. Unfortunately it is based on the original date, so you may have to scroll back pretty far:

Recover Deleted GIT Commits

Once you’ve located your missing commit, all you have to do is create a branch at that commit, and you’ve recovered your data!

Recover Deleted GIT Commits