If I run git branch -d XYZ
, is there a way to recover the branch? Is there a way to go back as if I didn\'t run the delete branch command?
If you don't have a reflog, eg. because you're working in a bare repository which does not have the reflog enabled and the commit you want to recover was created recently, another option is to find recently created commit objects and look through them.
From inside the .git/objects
directory run:
find . -ctime -12h -type f | sed 's/[./]//g' | git cat-file --batch-check | grep commit
This finds all objects (commits, files, tags etc.) created in the last 12 hours and filters them to show only commits. Checking these is then a quick process.
I'd try the git-ressurect.sh script mentioned in Jakub's answer first though.