在Git中删除后可以恢复分支吗? [英] Can I recover a branch after its deletion in Git?

查看:125
本文介绍了在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.

这篇关于在Git中删除后可以恢复分支吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆