在Git中删除后可以恢复分支吗?
问题描述:
如果我运行 git branch -d XYZ
,有没有办法恢复分支?有没有办法回去,就好像我没有运行删除分支命令?
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?
答
是的,你应该可以做 git reflog
,然后在你删除的分支的顶端找到提交的SHA1,然后只需 git checkout [sha]
。一旦你提交了,你可以 git checkout -b [branchname]
来重新创建分支。
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 checkout -b [branchname]
to recreate the branch from there.