Git撤消本地分支删除 [英] Git undo local branch delete

查看:446
本文介绍了Git撤消本地分支删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚删除了错误的分支,其中包含一些实验性更改,我需要使用 git branch -D branchName

I just deleted the wrong branch with some experimental changes I need with git branch -D branchName.

如何恢复分支?

推荐答案

您可以使用 git reflog 来查找分支上次提交的SHA1。从这一点开始,您可以使用

You can use git reflog to find the SHA1 of the last commit of the branch. From that point, you can recreate a branch using

git branch branchName <sha1>

编辑:@seagullJS表示,分支-D 命令告诉你sha1,所以如果你还没有关闭终端,它变得很容易。例如,这将删除并立即恢复名为 master2 的分支:

As @seagullJS says, the branch -D command tells you the sha1, so if you haven't closed the terminal yet it becomes real easy. For example this deletes and then immediately restores a branch named master2:

user@MY-PC /C/MyRepo (master)
$ git branch -D master2
Deleted branch master2 (was 130d7ba).    <-- This is the SHA1 we need to restore it!

user@MY-PC /C/MyRepo (master)
$ git branch master2 130d7ba

这篇关于Git撤消本地分支删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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