自动重新分配Git子分支 [英] Automatically rebase Git sub-branches

查看:134
本文介绍了自动重新分配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 code> topic2 不是。我想知道:

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

但如果我简单地做 git rebase topic1 topic2 ,Git会尝试在 E'顶部重播提交 E F code>和 F',这会失败,因为它们编辑了相同文件的相同行。所以我必须像这样运行一些笨重的东西:

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

...这需要做一个 git log 鼠标就像某种失败者!))。我知道这并不令人心碎,但这种使用模式对Git来说必须是相当常见的。任何人都可以想出一种方法来一举颠覆 topic1 topic2 吗?


Nils_M 在评论中指出,rebase手册页表示注意 HEAD中的任何提交都会引入与HEAD中的提交相同的文本更改。< upstream> (即已经接受上一个补丁的补丁信息或时间戳将被跳过)。



Git重播的唯一原因在 topic2 转化为<$期间, E F c $ c> topic1 如果 E' F'原稿。在这种情况下,当因为合并冲突而导致基金停止时,只需使用 git rebase --skip


Say I have a git history like this:

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

That is, I have two topic branches, where one feature depends upon another. In the meantime, work has been done on master, so I want to rebase topic1. This results in:

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

That is, topic1 was rebased but topic2 was not. I want to get to this:

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

But if I simply do git rebase topic1 topic2, Git will try to replay commits E and F on top of E' and F', which will fail because they edit the same lines of the same files. So I have to run something unwieldy like this:

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

... which requires doing a git log and copy-pasting something (using the mouse like some sort of loser!). I know this isn't exactly heartbreaking, but this usage pattern must be fairly common for Git. Can anyone think of a way to rebase topic1 and topic2 in one fell swoop?

解决方案

As Nils_M pointed out in a comment, the rebase man page says Note that any commits in HEAD which introduce the same textual changes as a commit in HEAD..<upstream> are omitted (i.e., a patch already accepted upstream with a different commit message or timestamp will be skipped).

The only reason Git would replay E and F during the rebase of topic2 onto topic1 is if E' or F' has been modified from their originals. In that case, when the rebase stops due the merge conflict, simply use git rebase --skip.

这篇关于自动重新分配Git子分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆