如何在最近的合并之后仅对提交进行重新绑定? [英] How to rebase only the commits after the latest merge?

查看:109
本文介绍了如何在最近的合并之后仅对提交进行重新绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下情况:


  1. 我检出了一个来自master的分支

  2. 提交

  3. 我合并了更新后的主文件

  4. 我做了更多提交

  5. 现在我想从点4以便来自点2的提交不受影响。

所以,如果我最初有:

  x  -  x  -  x  -  x  -  x  -  x  -  x master 
\\\
y - y- -Y - y - y dev
(2)(3)(4)

我想得到:

 (1)(2)
x - x - x - x --x - x - x master
\\
y - y -------- Y' - y' - y'dev
( 2)(5)(5)

如果我只是做 git rebase master 它将rebase提交2和4并从3删除合并。这不是我想要的。

也可以选择 git merge master ,然后 git rebase -i - 合并之前从3提交并从3合并后移动最后一个合并,然后从3合并/压缩到合并。更新:它不起作用简单。 Git拒绝压缩两个合并。这个问题: git rebase interactive:squash merge commits together

解决方案

使用我和VonC的答案可以实现更自动化的解决方案:

  git checkout -b tmp Y 
git merge master
git reset --soft HEAD ^^
git rev-parse master> .git / MERGE_HEAD
git commit -CY
git checkout -
git rebase --onto tmp Y
git branch -d tmp



是合并提交被扩展。



它的工作原理是这样的:

  x  -  x  -  x  -  x  -  x  -  x  -  x master 
\ \\ \\
y - y - y - y - y dev

x - x - x - x - x - x - x master
| \
\ Y tmp
\ / \
y - y y - y dev

x - x - x - x --x - x - x master
| \\\
\ Y ----- Y'tmp
\ / \
y - y y - y dev

x --x - x - x - x - x - x master
| \
| ------- Y'tmp
\ /
y - y - Y - y - y dev

x - x - x --x - x - x - x master
| \
| ------- Y'tmp
\ / \
y - y y - y dev

x - x - x - x --x - x - x master
\\
y - y -------- Y' - y - y dev


Consider following scenario:

  1. I checked out a branch from master
  2. I made some commits
  3. I merged updated master
  4. I made some more commits
  5. Now I want rebase commits from point 4 so that commits from point 2 are not affected.

So if I have initially:

     (1)         (2)
x--x--x--x--x--x--x         master
       \     \
        y--y--Y--y--y       dev
          (2)(3)   (4)

I want to get:

     (1)         (2)
x--x--x--x--x--x--x             master
       \           \
        y--y--------Y'--y'--y'  dev
          (2)      (5)     (5)

If I just do git rebase master it will rebase commits both from 2 and from 4 and delete merge from 3. It's not what I want.

There is also option to do git merge master, then git rebase -i -p before the merge commit from 3 and move the last merge after the merge from 3 and do fixup/squash it into the merge from 3. Update: it does not work that easy. Git refuses to squash two merges. This problem: git rebase interactive: squash merge commits together .

解决方案

Using my and VonC's answers made more automate-able solution:

git checkout -b tmp Y
git merge master 
git reset --soft HEAD^^ 
git rev-parse master > .git/MERGE_HEAD 
git commit -C Y
git checkout -
git rebase --onto tmp Y
git branch -d tmp

Y - is the merge commit to be extended.

And it works like this:

x--x--x--x--x--x--x         master
       \     \
        y--y--Y--y--y       dev

x--x--x--x--x--x--x         master
      |      \
       \      Y             tmp
        \    / \
         y--y   y--y        dev

x--x--x--x--x--x--x         master
      |      \     \
       \      Y-----Y'      tmp
        \    / \
         y--y   y--y        dev

x--x--x--x--x--x--x         master
      |            \
      |      -------Y'      tmp
       \    /
        y--y--Y--y--y       dev

x--x--x--x--x--x--x         master
      |            \
      |      -------Y'      tmp
       \    /        \
        y--y          y--y  dev

x--x--x--x--x--x--x           master
       \           \
        y--y--------Y'--y--y  dev

这篇关于如何在最近的合并之后仅对提交进行重新绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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