合并/重新绑定Git中'已断开'的分支 [英] Merge/rebase a 'disconnected' branch in Git
问题描述
假设我们在Git中有以下情况:
$ $ p $ $ $ $ c $ X $ Y
$ $ b A --- B --- C --- D边缘
现在我将 edge
分支改变B提交一点点(使用 edit
),现在看起来像这样:
X --- Y特征
A --- E --- C'--- D'边缘
C和D是与C和D相同的提交,但应用于E之上(并注意特性
分支中的X变为断开连接)。
现在我该怎么做:
- 重新合并/合并
特性
分支,使其提交显示为好像它们应用于D'之上一样? - 重新合并/合并
特性
分支,使其提交显示为好像它们应用于E之上一样,但没有单独的'合并分支...'提交(并且C'和D'被重写为C'和D')?
X
原始 B
作为其父项。如果您想随后在边缘
顶部重新标记 feature
,则:
git checkout feature
git rebase edge
如果您希望更改树,使其具有与原始版本类似的结构,但 X
作为 E
,即:
git结帐功能
git rebase --onto< sha-of -E> SHA-的-B个其中p功能
Suppose we have the following situation in Git:
X---Y feature
/
A---B---C---D edge
Now I rebase the edge
branch changing the B commit a little bit (using edit
) so it now looks like this:
X---Y feature
A---E---C'---D' edge
C' and D' are the same commits as C and D, but applied on top of E (and notice that X within the feature
branch became disconnected).
Now how can I:
- Rebase/merge the
feature
branch so that its commits appear as if they were applied on top of D'? - Rebase/merge the
feature
branch so that its commits appear as if they were applied on top of E, but without a separate 'merging branch ...' commit (and with C' and D' being rewritten to become C'' and D'')?
X
doesn't become disconnected per-se, it still has the original B
as its parent. If you want to subsequently rebase feature
on top of edge
, then:
git checkout feature
git rebase edge
If you wish to change the tree so that it has a similar structure to the original version, but with X
as a child of E
, that's:
git checkout feature
git rebase --onto <sha-of-E> <sha-of-B> feature
这篇关于合并/重新绑定Git中'已断开'的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!