zoukankan      html  css  js  c++  java
  • git revert和git reset的区别

    git revert 是撤销某次操作,此次操作之前的commit都会被保留
    git reset 是撤销某次提交,但是此次之后的修改都会被退回到暂存区
    具体一个例子,假设有三个commit, git st:
    commit3: add test3.c
    commit2: add test2.c
    commit1: add test1.c
    当执行git revert HEAD~1时, commit2被撤销了
    git log可以看到:
    commit1:add test1.c
    commit3:add test3.c
    git status 没有任何变化
    如果换做执行git reset --soft(默认) HEAD~1后,运行git log
    commit2: add test2.c
    commit1: add test1.c
    运行git status, 则test3.c处于暂存区,准备提交。
    如果换做执行git reset --hard HEAD~1后,
    显示:HEAD is now at commit2,运行git log
    commit2: add test2.c
    commit1: add test1.c
    运行git st, 没有任何变化
    另外:
    git revert <commit log string>是撤消该commit,作为一个新的commit。
  • 相关阅读:
    C# 5注释
    C# 4关键字
    C# 3练习题
    python之子类调用父类的同名属性和方法
    python之继承
    python之对象删除和输出
    python之r,w,a
    python之类中的方法和属性
    python之面向对象
    python之os对文件的操作
  • 原文地址:https://www.cnblogs.com/netliang/p/Git.html
Copyright © 2011-2022 走看看