zoukankan      html  css  js  c++  java
  • Git版本回退

    Git中,每次commit提交都会生成一个历史纪录。使用 git log 查看commit历史:

    $ git log --oneline 
    ec88247 modifyed bar.html,foo.txt add new.txt
    47384c8 modify bar.html in clone again
    31e1f6f modify foo.txt in original again
    8747b24 Merge branch 'master' of /home/mrbird/projects/first-project
    27b76ec modify foo.txt in original
    796e40d modify bar.html in clone
    8e1b132 modify foo.txt,add 'hello msg'
    94418b1 add bar.html,modify foo.txt,delete bar.txt
    c2e4810 add foo.txt bar.txt

     

     

    每个记录都有一个与之对应的commit id,所以可以使用命令git reset --hard commit_id来回退到相应的版本。除此之卡,在Git中,使用HEAD来代表当前版本,如需回退到前一个版本,可以使用命令git reset --hard HEAD^,前两个版本则用HEAD~2表示,以此类推。

    当前版本id为ec88247…比如,现要回退到commit_id为47384c8…的版本,可以使用如下命令:

    $ git reset --hard 47384c8
    HEAD is now at 47384c8again modify bar.html in clone

     

    或:

    $ git reset --hard HEAD^
    HEAD is now at 47384c8 modify bar.html in clone again

     

    再次查看commit历史:

    $ git log --oneline 
    47384c8 modify bar.html in clone again
    31e1f6f modify foo.txt in original again
    8747b24 Merge branch 'master' of /home/mrbird/projects/first-project
    27b76ec modify foo.txt in original
    796e40d modify bar.html in clone
    8e1b132 modify foo.txt,add 'hello msg'
    94418b1 add bar.html,modify foo.txt,delete bar.txt
    c2e4810 add foo.txt bar.txt

     

    可发现,commit_id为ec88247…的记录已经不见了,如果要回退到这个版本,又忘记了与之对应的commit_id该怎么办呢。这时候可以使用git reflog命令来查看操作历史:

    $ git reflog
    47384c8 HEAD@{0}: reset: moving to 47384c8
    ec88247 HEAD@{1}: reset: moving to ec88247
    ...

     

    可看到,回退到commit_id为47384c8…的上一个版本的commit_id为ec88247…,所以,使用如下命令即可回到一开始回退前的版本:

    $ git reset --hard ec88247
    HEAD is now at ec88247 modifyed bar.html,foo.txt add new.txt

  • 相关阅读:
    异常处理(throw,throws,try,catch,finally)
    内部类、匿名内部类、静态内部类
    Object,equals,toString
    有关于多态和静态绑定与动态绑定的知识
    接口的基本知识
    关于继承的基本知识,方法重写,final和abstract的使用, 动态绑定和静态绑定的知识
    设计模式: 单列设计模式 、模块方法设计模式、装饰设计模式、工厂设计模式、适配器设计模式
    zabbix设置维护周期
    zabbix入门
    yum安装zabbix 5.0 LTS
  • 原文地址:https://www.cnblogs.com/7788IT/p/11625646.html
Copyright © 2011-2022 走看看