zoukankan      html  css  js  c++  java
  • how to restore 'git reset –hard' operations

    how to restore 'git reset –hard' operations

    1 emulate git reset –hard

     

    1.1 generate two commits

    $ mkdir tt; cd tt
    $ git init
    $ touch foo.txt
    $ git add foo.txt
    $ git commit -m "init"
    $ echo "data" >> foo.txt
    $ git commit -a -m "data"
    

    1.2 check the commits

    tt$ git log --pretty=oneline 
    48152f95f5e993ab167a02e76b43fa998c40b750 data
    a8daade8ffd7a4ccf23b145c7a380391068e8ed2 init
    

    1.3 reset –hard to the first commit

    tt$ git reset --hard a8daade
    HEAD is now at a8daade init
    
    tt$ git log --pretty=oneline 
    a8daade8ffd7a4ccf23b145c7a380391068e8ed2 init
    

    2 restore to the second commit (lost after 'git reset –hard')

     

    2.1 check reflog

    reflog will note down all HEAD history. The 'reset', 'checkout' operations will be noted in reflog.

    tt$ git reflog 
    a8daade HEAD@{0}: reset: moving to a8daade
    48152f9 HEAD@{1}: commit: data
    a8daade HEAD@{2}: commit (initial): init
    

    2.2 restore

    tt$ git reset --hard 48152f9
    HEAD is now at 48152f9 data
    
    tt$ git log --pretty=oneline 
    48152f95f5e993ab167a02e76b43fa998c40b750 data
    a8daade8ffd7a4ccf23b145c7a380391068e8ed2 init
    
     
  • 相关阅读:
    吴恩达《机器学习》第四章:多元线性回归
    吴恩达《机器学习》第三章:矩阵和向量
    吴恩达《机器学习》第二章:线性回归
    吴恩达《机器学习》第一章:监督学习和无监督学习
    初学Go语言的学生管理系统
    vscode如何自定义补全内容,自定义常用的快捷方式?
    vscode配置Golang环境所需的bin文件夹(各种包)
    Google浏览器一开启就提示“请停用以开发者模式运行的扩展程序“解决方案
    一道把递归、链表、引用、双指针都结合的题——回文链表
    grep
  • 原文地址:https://www.cnblogs.com/aqing1987/p/5387039.html
Copyright © 2011-2022 走看看