zoukankan      html  css  js  c++  java
  • git 学习(2)--恢复版本

    查看修改历史记录

    $ git log
    
    commit fba77877d316436c1b774b8933380ebcac668040
    Author: keith <ustbfxx@163.com>
    Date:   Fri Jan 16 01:34:06 2015 +0800
    
        add a git instance
    
    commit 148ff70cb26b4805609ada5f95436e002490adb9
    Author: keith <ustbfxx@163.com>
    Date:   Wed Jan 14 04:14:20 2015 +0800
    
        add good study
    
    commit 69a629d7ec0e0c9f582fb26bb50e5974b18c55a3
    Author: keith <ustbfxx@163.com>
    Date:   Tue Jan 13 22:51:10 2015 +0800
    
        create readme.txt file
     
    

    如果我们嫌输出信息太多,可以加上--pretty=oneline

     $ git log --pretty=oneline
     fba77877d316436c1b774b8933380ebcac668040 add a git instance
     148ff70cb26b4805609ada5f95436e002490adb9 add good study
     69a629d7ec0e0c9f582fb26bb50e5974b18c55a3 create readme.txt file 
    

    这里fba77877..8040commit id版本号,是通过SHA1计算出来的一个非常大的数字

    回退到上一个版本

     $ git reset --hard HEAD^
     HEAD is now at 148ff70 add good study
     $ cat readme.txt
     good git
     git is a file version control system
     good good study
    

    可以看出已经回到上一个版本,那如何在返回原来的版本呢

     $ git reset --hard fba77877
     HEAD is now at fba7787 add a git instance
     $ cat readme.txt
     good git
     git is a file version control system
     good good study
     Git git=new Git();
    

    这里的commit id不需要输入全部,不过也不能太少,不然git会无法确定是那一个,HEAD指向commit id直接会返回到这个版本号。这些版本号git都是有记录的,我们通过git reflog来查找输入的命令,可以指向我们要返回的commit id

    $ git reflog
    fba7787 HEAD@{0}: reset: moving to fba77877
    148ff70 HEAD@{1}: reset: moving to HEAD^
    fba7787 HEAD@{2}: commit: add a git instance
    148ff70 HEAD@{3}: commit: add good study
    69a629d HEAD@{4}: commit (initial): create readme.txt file
    

    总结命令

    $ git log --pretty=online//查看提交的次数和commit id
    $ git reset --hard HEAD^ //回到上一个版本
    $ git reset --hard commit_id //返回某一个commit_id 的版本
    $ git reflog //查看提交的命令
    

    正确的步骤是 修改完后 使用 git add命令,再提交,如果重新修改后没有使用add命令,提交之后新修改的是不会提交的。

  • 相关阅读:
    Warning: Cannot modify header information
    curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in
    PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings.
    出现Deprecated: Function ereg_replace() is deprecated in 的原因及解决方法
    APMServ5.2.6 升级PHP版本 到高版本 5.3,5.4
    Apache无法启动解决 the requested operation has failed
    用json获取拉钩网的信息
    json
    如何用组件组装一个简单的机器人
    vue-组件
  • 原文地址:https://www.cnblogs.com/keithmoring/p/4227608.html
Copyright © 2011-2022 走看看