recovering a deleted branch using git reflog
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
Mmmh git.