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?
I used the following commands to find and retrieve my deleted branch. The first steps are from gcb's description.
$ git fsck --full --no-reflogs --unreachable --lost-found > lost
$ cat lost | cut -d\ -f3 > commits
$ cat commits | xargs -n 1 git log -n 1 --pretty=oneline
Now look for the git commit id (GIT-SHA) based on the commit comments and use it in the command below. Checkout a new branch called NEW-BRANCH with the previously found GIT-SHA:
$ git checkout -b NEW-BRANCH GIT-SHA