git 误删分支恢复方法

1.创建分支 abc

git branch abc

 
2.查看分支列表

git branch -a
  abc
* develop
  remotes/origin-dev/develop

 
3.切换到abc分支,随便修改一下东西后 commit

# 切换分支
git checkout abc

# 创建一个文件
echo 'abc' > test.txt

# 提交
git add .
git commit -m 'add test.txt'

 
4.删除分支abc

git branch -D abc

 
5.查看分支列表,abc分支已不存在

git branch -a
* develop
  remotes/origin-dev/develop

 
恢复步骤如下:
1.使用git log -g 找回之前提交的commit

commit 3eac14d05bc1264cda54a7c21f04c3892f32406a
Reflog: HEAD@{1} (fdipzone <fdipzone@sina.com>)
Reflog message: commit: add test.txt
Author: fdipzone <fdipzone@sina.com>
Date:   Sun Jan 31 22:26:33 2016 +0800

    add test.txt

 
2.使用git branch recover_branch[新分支] commit_id命令用这个commit创建一个分支

git branch recover_branch_abc 3eac14d05bc1264cda54a7c21f04c3892f32406a

git branch -a
* develop
  recover_branch_abc
  remotes/origin-dev/develop

 
3.切换到recover_branch_abc分支,检查文件是否存在

git checkout recover_branch_abc
Switched to branch 'recover_branch_abc'

ls -lt
total 8
-rw-r--r--   1 fdipzone  staff     4  1 31 22:38 test.txt

 

https://blog.csdn.net/fdipzone/article/details/50616386

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值