Can I recover a branch after its deletion in Git?

后端 未结 20 2320
广开言路
广开言路 2020-11-22 05:53

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?

20条回答
  •  迷失自我
    2020-11-22 06:31

    If you removed the branch and forgot it's commit id you can do this command:

    git log --graph --decorate $(git rev-list -g --all)
    

    After this you'll be able to see all commits. Then you can do git checkout to this id and under this commit create a new branch.

提交回复
热议问题