zoukankan      html  css  js  c++  java
  • git revert 让提交不再害怕

    git revert 让提交不再害怕

    使用了好多命令, 但对于 git revert 一直不敢怎么使用, 为什么呢?
    因为 git merge 的存在.

    每次 对于 git merge 的分支, 执行 git revert xxx 分支的时候总是报错. 没有细追.
    今天同事恰好问道了这个问题. 于是追了一下.

    主要就是对于 -m 命令. 查看了一下,其中对于

    git revert -m 
    

    解释如下

     -m parent-number, --mainline parent-number
               Usually you cannot revert a merge because you do not know which side of the merge should be considered the mainline. This option specifies the
               parent number (starting from 1) of the mainline and allows revert to reverse the change relative to the specified parent.
    
               Reverting a merge commit declares that you will never want the tree changes brought in by the merge. As a result, later merges will only bring
               in tree changes introduced by commits that are not ancestors of the previously reverted merge. This may or may not be what you want.
    
               See the revert-a-faulty-merge How-To[1] for more details.
    

    正常使用的话, 那么直接执行

    git revert xxx(具体的某次提交的 SHA-1)
    

    如果有某次merge的话

    git revert -m 1 xxx (具体的某次提交)
    

    这里的 1 是什么意思呢?

    运行 git log 后, 当前的提交信息一般如下
    commit
    Merge:
    Author:
    Date:

    其中的 merge 第一个就是 1, 第二个就是 2, 依次计算;

    一个比较好的参考地址如下:
    how to revert-a-faulty-merge

  • 相关阅读:
    策略模式
    装饰模式
    责任链模式
    算法_快速排序
    算法_二分查找
    数据结构学习笔记_表
    集合遍历remove时ConcurrentModificationException异常
    LinkedHashMap笔记
    Windows相关命令
    高效率幂运算
  • 原文地址:https://www.cnblogs.com/asdfq/p/9297427.html
Copyright © 2011-2022 走看看