If I run 'git branch -d XYZ' to delete branch 'XYZ', is there a way to recover the branch. Or, in other words, is there a way to go back as if I didn't run the branch delete command?
+4
A:
Yes, you should be able to do git reflog
and find the SHA1 for the commit at the tip of your deleted branch, then just git checkout [sha]
. And once you're at that commit, you can just git co -b [branchname]
to make a recreate the branch from there.
tfe
2010-09-04 03:43:13
You can do it in one step: `git checkout -b <branch> <sha>`.
Jefromi
2010-09-04 14:19:33
+1
A:
Adding to tfe answer: there is also git-ressurect.sh script in the contrib/
area of git sources (in git.git repository), which might help you.
Jakub Narębski
2010-09-06 19:39:08