重新合并提交 [英] Rebase a merge commit
问题描述
假设我的Git仓库最初有两个分支:Foo和Bar。
Suppose my Git repository initially has two branches: Foo and Bar.
... ─ Foo
... ─ Bar
我创建了第三个分支FooBar,我在其中将两个分支合并在一起。
I create a third branch, FooBar in which I commit the merge of the two other branches.
... ─ Foo ──┐
FooBar
... ─ Bar ──┘
FooBar现在是Foo和Bar之前的一次提交。接下来,我做了一些更多的工作,仅在Foo提交了几次。
FooBar is now one commit ahead of both Foo and Bar. Next, I do some more work, committing a few times on Foo only.
... ── A ───┬── B ── C ── D ── Foo
FooBar
... ─ Bar ──┘
问题是:由于分支FooBar的第一个父项不再是Foo,我可以重新分支FooBar中的合并提交以再次将Foo和Bar作为它的两个父项吗?换句话说,我是否可以将Foo中的开发与未改变的Bar一起并入到之前合并的FooBar中?
The question is: since the first parent of branch FooBar is no longer Foo, can I rebase the merge commit in branch FooBar to again have Foo and Bar as its two parents? In other words, can I incorporate the development in Foo into the previously merged FooBar along with the unchanged Bar?
... ── A ── B ── C ── D ── Foo ──┐
FooBar
... ─ Bar ───────────────────────┘
推荐答案
我意识到这是一个相当古老的话题,但自从我发现这个问题的同时
I realize this is quite an old topic but since I found this question while facing a similar situation I could as well tell what I used in the end.
git checkout FooBar
git rebase -p --onto Foo A
我尝试使用原始问题中的名称。特别注意, A
表示在ascii艺术中标记为A的提交。您可能会使用提交的散列或其他任何方式来指向分支 Foo
和 FooBar
的提交。最初是分开的。
I tried to use the names from the original question. Note especially that A
means the commit that is marked as A in the ascii art. You would probably use the hash of the commit instead or any other way to point to the commit where branches Foo
and FooBar
originally separate.
- preserve-merges
,它的功能与它所说的完全相同。
The -p
flag is also known as --preserve-merges
and it does pretty much what it says.
请注意,分支 Bar
doesn在这里扮演一个角色,这样提交行可能是一个命名分支,或者不是 - 它没有区别。
Note that the branch Bar
doesn't play a role here so that line of commits might be a named branch or then not - it makes no difference.
这篇关于重新合并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!