zoukankan      html  css  js  c++  java
  • 撤销 git reset --hard HEAD~1

    方法一:

    1.先通过git reflog找到上一次的历史提交记录id,git如果没有特意设置,是会保存记录一段时间的(a few days or a month)

    2.git reset --hard [id]

     

    方法二:

    git reset --hard HEAD@{1}

    直接回到刚才的那个结点,{}中表示的是结点的序号

     

    方法一的例子如下:

    $ git init

    Initialized empty Git repository in .git/

     

    $ echo "testing reset" > file1

    $ git add file1

    $ git commit -m 'added file1'

    Created initial commit 1a75c1d: added file1

     1 files changed, 1 insertions(+), 0 deletions(-)

     create mode 100644 file1

     

    $ echo "added new file" > file2

    $ git add file2

    $ git commit -m 'added file2'

    Created commit f6e5064: added file2

     1 files changed, 1 insertions(+), 0 deletions(-)

     create mode 100644 file2

     

    $ git reset --hard HEAD^

    HEAD is now at 1a75c1d... added file1

     

    $ cat file2

    cat: file2: No such file or directory

     

    $ git reflog

    1a75c1d... HEAD@{0}: reset --hard HEAD^: updating HEAD

    f6e5064... HEAD@{1}: commit: added file2

     

    $ git reset --hard f6e5064

    HEAD is now at f6e5064... added file2

     

    $ cat file2

    added new file

     

  • 相关阅读:
    NOJ 1116 哈罗哈的大披萨 【淡蓝】 状态压缩DP
    优先队列原理与实现【转】
    testC-I
    济南NOIP冬令营 选拔(select)
    P4747 D’s problem(d)
    P4746 C’s problem(c)
    P4745 B’s problem(b)
    P4744 A’s problem(a)
    [bzoj] 1004: [HNOI2008]Cards
    NOIP2013 表达式求值
  • 原文地址:https://www.cnblogs.com/luojinping/p/3283505.html
Copyright © 2011-2022 走看看