合并/重新绑定Git中的"断开连接"分支

Paw*_*cki 5 git branching-and-merging

假设我们在Git中有以下情况:

      X---Y feature
     /
A---B---C---D edge
Run Code Online (Sandbox Code Playgroud)

现在我重新edge修改分支,稍微更改B提交(使用edit),所以它现在看起来像这样:

      X---Y feature

A---E---C'---D' edge
Run Code Online (Sandbox Code Playgroud)

C'和D'是与C和D相同的提交,但是应用于E的顶部(并注意到feature分支内的X 断开连接).

现在我该怎么办:

  1. 重新绑定/合并feature分支,使其提交看起来好像是在D'上面应用的?
  2. 重新绑定/合并feature分支,使其提交看起来好像它们被应用在E之上,但是没有单独的"合并分支......"提交(并且C'和D'被重写成C'和D' ")?

nic*_*rim 5

X本身不会断开连接,它仍然将原始内容B作为其父级.如果你想变基随后feature之上edge,则:

git checkout feature
git rebase edge
Run Code Online (Sandbox Code Playgroud)

如果您希望更改树,使其具有与原始版本类似的结构,但X作为子项E,则为:

git checkout feature
git rebase --onto <sha-of-E> <sha-of-B> feature
Run Code Online (Sandbox Code Playgroud)