【问题标题】:Automatically rebase Git sub-branches自动变基 Git 子分支
【发布时间】:2015-09-18 12:40:54
【问题描述】:

假设我有这样的 git 历史:

A--B--C--D <master>
   \--E--F <topic1>
         \--G <topic2>

也就是说,我有两个主题分支,其中一个功能依赖于另一个功能。同时,master 的工作已经完成,所以我想重新定位topic1。这导致:

A--B--C--D <master>
   |     \--E'--F' <topic1>
   \--E--F--G <topic2>

也就是说,topic1 已重新设置基础,但 topic2 没有。我想解决这个问题:

A--B--C--D <master>
         \--E'--F' <topic1>
                \--G <topic2>

但如果我只是简单地执行git rebase topic1 topic2,Git 将尝试在E'F' 之上重放提交EF,这将失败,因为它们编辑相同文件的相同行。所以我必须像这样运行一些笨拙的东西:

git rebase --onto topic1 <sha1-of-commit-F> topic2

... 这需要做一个git log 并复制粘贴一些东西(使用mouse 就像某种loser!)。我知道这并不令人心碎,但这种使用模式对于 Git 来说一定是相当普遍的。任何人都可以想出一种方法来一举重定topic1topic2

【问题讨论】:

  • 根据 rebase 手册页,Note that any commits in HEAD which introduce the same textual changes as a commit in HEAD..&lt;upstream&gt; are omitted (i.e., a patch already accepted upstream with a different commit message or timestamp will be skipped). 您建议的命令应该可以正常工作。
  • 嗯...我没有意识到这一点。我可能对导致我的变基失败的原因感到困惑。我会调查并回到这个问题。谢谢
  • 当您的E'F' 与冲突合并时,您可能会遇到冲突,因为差异会发生变化。
  • 好的,我已经意识到发生这种情况的原因(很明显,现在看来)是当我修改E' 时,它不再引入与E 相同的更改。并非每次提交都会发生这种情况。在这些情况下,解决方案似乎只是使用git rebase --skip

标签: git version-control branch rebase


【解决方案1】:

正如Nils_M 在评论中指出的那样,变基手册页上写着Note that any commits in HEAD which introduce the same textual changes as a commit in HEAD..&lt;upstream&gt; are omitted (i.e., a patch already accepted upstream with a different commit message or timestamp will be skipped).

Git 在topic2 变基到topic1 期间重播EF 的唯一原因是E'F' 是否已从其原始版本修改。在这种情况下,当 rebase 由于合并冲突而停止时,只需使用 git rebase --skip

【讨论】:

    猜你喜欢
    • 2016-09-20
    • 2015-03-28
    • 1970-01-01
    • 2012-10-27
    • 2011-02-05
    • 2020-07-04
    • 1970-01-01
    • 2014-03-20
    • 1970-01-01
    相关资源
    最近更新 更多