【问题标题】:Having problems with "git revert" after merging my branch合并我的分支后出现“git revert”问题
【发布时间】:2015-12-27 14:16:35
【问题描述】:

我有三个分支:master、A、B。

分支“A”和“B”应该相互独立。拉取请求后,master 从 A 和 B 更新。现在,我不小心将 B 合并到 A。

我立即通过git revert -m 恢复了此合并

但是现在当我将 B 拉入 master 时,A 中的恢复合并会破坏分支 B 的更改。这是因为分支 A 有“恢复合并 B”提交。

如何删除“还原合并分支 B”和“合并分支 B”提交? 我尝试使用 git -rebase 命令,但它对我没有帮助,git 创建了一个不在拉取请求中的分支。

【问题讨论】:

    标签: git github


    【解决方案1】:

    简单回答: git docs

    revert 因为

    因此,如果您将“还原”视为“撤消”,那么您将始终 错过这部分回复。是的,它会撤消数据,但不,它不会 撤消历史记录。

    添加更多内容:

    不幸的是,你遇到了 git 用户历史上最流行的问题 :)

    您的问题是错误合并git merge branch B/branch A,您尝试通过git revert 恢复它

    记住,所以“还原”会撤消数据更改,但它不是 “撤消”是指它不会撤消提交对 存储库历史记录。

    我认为更适合回答这个问题的人是linus torvalds,我找不到比他更好的人了。

    Reverting a regular commit just effectively undoes what that commit
    did, and is fairly straightforward. But reverting a merge commit also
    undoes the _data_ that the commit changed, but it does absolutely
    nothing to the effects on _history_ that the merge had.
    
    So the merge will still exist, and it will still be seen as joining
    the two branches together, and future merges will see that merge as
    the last shared state - and the revert that reverted the merge brought
    in will not affect that at all.
    
    So a "revert" undoes the data changes, but it's very much _not_ an
    "undo" in the sense that it doesn't undo the effects of a commit on
    the repository history.
    
    So if you think of "revert" as "undo", then you're going to always
    miss this part of reverts. Yes, it undoes the data, but no, it doesn't
    undo history.
    

    一些解决git revert问题的链接:

    1. Undo a git merge (hasn't been pushed yet)

    2. git revert, reset and merge problems

    【讨论】:

    • 非常感谢您链接到 Linus 的解释。我敦促您阅读整篇文章,因为我的问题在 and 的最后一张图中;)
    猜你喜欢
    • 2011-07-21
    • 1970-01-01
    • 2013-01-15
    • 1970-01-01
    • 1970-01-01
    • 2019-05-03
    • 2021-03-08
    • 2018-11-12
    • 2017-08-30
    相关资源
    最近更新 更多