合并/重新绑定Git中'已断开'的分支 [英] Merge/rebase a 'disconnected' branch in Git

查看:237
本文介绍了合并/重新绑定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变为断开连接)。



现在我该怎么做:


  1. 重新合并/合并特性分支,使其提交显示为好像它们应用于D'之上一样?

  2. 重新合并/合并特性分支,使其提交显示为好像它们应用于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:

  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'')?

解决方案

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屋!

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