Git: Recover a deleted branch

So after finishing something on a topic branch called “gamelan”, i wanted to switch back to the master branch, so this is what i just did:

$ git checkout master
    $ git branch -D gamelan

Shoot! Now in a i just deleted the branch without merging it beforehand. (Why, but why!?). Fortunatly Git has some divine powers which can help you recover. Git records your changes in a log, which you can show using git reflog:

$ git reflog
    bc2ff27 HEAD@{1}: checkout: moving from gamelan to master
    2cf094f HEAD@{2}: commit: WIP klangreihe gibt Noten zurück. Thread Beispiele
    8592aac HEAD@{3}: commit: WIP mehrere stimmen über gamelan scheduler
    ...

These commits are still “somewhere out there”. So to merge the changes from the deleted branch, i just merged the last commit from the deleted branch:

$ git merge 2cf094f

Article from http://blag.ahax.de/. I restored this article from Google’s cache, it helped me when I managed to do the same thing as the guy did with a git branch ( –_– ) So…Thank you!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s