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

    回退到上一个版本

    git reset --hard HEAD^
    git reset --hard HEAD~1

    回退到某一个版本

    git reflog
    git reset --hard commit_id

    准备环境:

    $ git init
    
    $ echo '1 commit' > test.txt
    $ git add .
    $ git commit -m '1 commit'
    
    $ echo '2 commit' > test.txt
    $ git add .
    $ git commit -m '2 commit'
    
    
    $ echo '3 commit' > test.txt
    $ git add .
    $ git commit -m '3 commit'
    
    $ echo '4 commit' > test.txt
    $ git add .
    $ git commit -m '4 commit'
    
    $ git log --oneline --all --graph --decorate
    * 1efcf18 (HEAD -> master) 4 commit
    * 6a7ace8 3 commit
    * 3be5879 2 commit
    * 3d1a4d4 1 commit

    回退一个版本

    $ git reset --hard HEAD^
    HEAD is now at 6a7ace8 3 commit
    
    $ cat test.txt
    3 commit
    
    $ git log --oneline --all --graph --decorate
    * 6a7ace8 (HEAD -> master) 3 commit
    * 3be5879 2 commit
    * 3d1a4d4 1 commit

    回退两个版本

    $ git reset --hard HEAD^^
    HEAD is now at 3d1a4d4 1 commit
    
    $ cat test.txt
    1 commit
    
    $ git log --oneline --all --graph --decorate
    * 3d1a4d4 (HEAD -> master) 1 commit

    回退到最新的那个版本(回去了)

    $ git reflog
    3d1a4d4 HEAD@{0}: reset: moving to HEAD^^
    6a7ace8 HEAD@{1}: reset: moving to HEAD^
    1efcf18 HEAD@{2}: commit: 4 commit
    6a7ace8 HEAD@{3}: commit: 3 commit
    3be5879 HEAD@{4}: commit: 2 commit
    3d1a4d4 HEAD@{5}: commit (initial): 1 commit
    
    $ git reset --hard 1efcf18
    HEAD is now at 1efcf18 4 commit
    
    xiaol@xiaol-PC MINGW64 /d/code/git_test (master)
    $ cat test.txt
    4 commit
    
    $ git log --oneline --all --graph --decorate
    * 1efcf18 (HEAD -> master) 4 commit
    * 6a7ace8 3 commit
    * 3be5879 2 commit
    * 3d1a4d4 1 commit
  • 相关阅读:
    Microsoft Visual studio2013 在c++中引用本地文件
    二叉树遍历
    二叉搜索树、B树
    01_C语言基础
    Linux网络应用编程之集线器(Packet Tracer仿真)
    Linux网络应用编程之Packet Tracer安装及界面介绍
    Linux网络应用编程之交换机概述
    Linux网络应用编程之VLAN(Packet Tracer仿真)
    ntp服务
    Failed to mount /sysroot如何解决?
  • 原文地址:https://www.cnblogs.com/413xiaol/p/10567696.html
Copyright © 2011-2022 走看看