在Git中恢复已删除的分支 [英] Recover deleted branch in Git

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

问题描述

  git分支-D demo 

但是我想恢复它...我在 git reflog

  541b2f5 HEAD @ {23}:结帐:从演示转移到主
06fa6d5 HEAD @ {24}:commit(合并) :删除用于删除变量和transfomers的ajax调用
b84b60a HEAD @ {25}:checkout:从demo1移动到demo

我想用sha 06fa6d5 创建分支,所以我试过了:

  git checkout -b demo 06fa6d5 

git checkout -b demo HEAD @ {24}

但是我没有从中得到代码...

解决方案

创建一个全部列表悬挂或无法访问的提交。

  git fsck --full --no-reflogs --unreachable --lost-found 

打印丢失中所有提交的提交消息列表并找到。

  ls -1 .git / lost-found / commit / | xargs -n 1 git log -n 1 --pretty = oneline 

通过这个过程找到你丢失的提交手动检查(即阅读)。
创建一个新的分支,将缺少的提交作为分支头。

  git checkout -b分支名称SHA 


I have deleted my branch by mistake like this:

git branch -D demo

But I want to recover it… I get this after git reflog

541b2f5 HEAD@{23}: checkout: moving from demo to master
06fa6d5 HEAD@{24}: commit (merge): remove ajax call for deleting variables and transfomers
b84b60a HEAD@{25}: checkout: moving from demo1 to demo

I want to create branch with sha 06fa6d5… so I tried this:

git checkout -b demo  06fa6d5

git checkout -b demo  HEAD@{24}

But I didn't get code from that…

解决方案

Create a list of all dangling or unreachable commits.

git fsck --full --no-reflogs --unreachable --lost-found

Print a list of commit messages for all commits in the lost and found.

ls -1 .git/lost-found/commit/ | xargs -n 1 git log -n 1 --pretty=oneline

Find your missing commit through the process of manual inspection (i.e. reading). Create a new branch with the missing commit as the branch head.

git checkout -b branch-name SHA

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

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