• git 删除分支恢复


    首先用以下步骤创建一个新分支,修改一些文件后删除,以便进行恢复。
    1.创建分支 abc

    git branch abc


    2.查看分支列表

    git branch -a

    abc* develop remotes/origin-dev/develop



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

    切换分支git checkout abcSwitched to branch 'abc'

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

    commit

    git add .git commit -m 'add test.txt'[abc 3eac14d] add test.txt 1 file changed, 1 insertion(+) create mode 100644 test.txt


    4.删除分支abc

    git branch -D abc

    Deleted branch abc (was 3eac14d).

    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.txtAuthor: 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

    可以见到recover_branch_abc已创建


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

    Switched to branch 'recover_branch_abc'ls -lttotal 8-rw-r--r-- 1 fdipzone staff 4 1 31 22:38 test.txt

    这样就可以恢复被误删的分支了

  • 相关阅读:
    线程操作共享变量的一点分享。
    C调用栈重温
    8051汇编命令记录。
    没事写个散列玩~
    Ubuntu切换root用户权限
    CEdit自动换行和状态栏添加
    基于原始套接字的嗅探器
    Windows录音API学习笔记
    Windows内存管理
    C语言中tm结构体
  • 原文地址:https://www.cnblogs.com/redBack/p/15196715.html
Copyright © 2020-2023  润新知