问题
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
featurebranch so that its commits appear as if they were applied on top of D'? - Rebase/merge the
featurebranch 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'')?
回答1:
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
来源:https://stackoverflow.com/questions/5349928/merge-rebase-a-disconnected-branch-in-git