Mar 23 git: recovering deleted branch

tags: git | comments

Have you ever overlooked and deleted a branch you did not wanted? I did today, but no wonder git is one of the best at its job.

The disaster came after (but could have been also: git reset —hard ):

$ git branch -D temp
$ git push origin :temp

Luckily git have lots of tools and safety nets, here are mine:

$ git log -g

that will walk reflog entries from the most recent one to older ones. There a found the one (the tip of the 5 commits I wiped):

commit 61c71a3f543ddd82e891529ad4288a51626b7a1d
Reflog: HEAD@{2} (Joaquin Rivera Padron <joahking@gmail.com>)
Reflog message: checkout: moving from edge to temp
Author: Joaquin Rivera Padron <joahking@gmail.com>
Date:   Sun Mar 22 20:29:35 2009 +0100

    ongoing specing FS with new geokit and country as country_code

After that:

$ gitk 61c71a3f543ddd82e891529ad4288a51626b7a1d &

showed what I lost, and cherry-picking them was a charm.

The tips were here and the git mailing list

blog comments powered by Disqus