如何在最近的合并之后仅对提交进行重新绑定? [英] How to rebase only the commits after the latest merge?
问题描述
请考虑以下情况:
- 我检出了一个来自master的分支
- 提交
- 我合并了更新后的主文件
- 我做了更多提交
- 现在我想从点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:
- I checked out a branch from master
- I made some commits
- I merged updated master
- I made some more commits
- 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屋!