Merge/rebase a 'disconnected' branch in Git

五迷三道 提交于 2019-12-07 06:01:07

问题


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:

  1. Rebase/merge the feature branch so that its commits appear as if they were applied on top of D'?
  2. 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'')?

回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!