我想要一个简单的解决方案,在交互式rebase期间压缩两个合并提交。git rebase interactive:squash merge commit在一起
我的库看起来像是:
X --- Y --------- M1 -------- M2 (my-feature)
/ / /
/ / /
a --- b --- c --- d --- e --- f (stable)
也就是说,我有一个my-feature
分支已合并两次近日,有没有真正之间提交英寸我不只是想变基的my-feature
分支,因为它是它自己的一个分支名,我只是想壁球在一起的最后两个合并提交到一个(没有公布这些提交尚)
X --- Y ---- M (my-feature)
/ /
/ /
a --- ... -- f (stable)
我想:
git rebase -p -i M1^
但我得到:
Refusing to squash a merge: M2
我终于做到的是:
git checkout my-feature
git reset --soft HEAD^ # remove the last commit (M2) but keep the changes in the index
git commit -m toto # redo the commit M2, this time it is not a merge commit
git rebase -p -i M1^ # do the rebase and squash the last commit
git diff M2 HEAD # test the commits are the same
现在,新的合并提交不再被视为合并提交(它只保留第一个父代)。所以:
git reset --soft HEAD^ # get ready to modify the commit
git stash # put away the index
git merge -s ours --no-commit stable # regenerate merge information (the second parent)
git stash apply # get the index back with the real merge in it
git commit -a # commit your merge
git diff M2 HEAD # test that you have the same commit again
但这可能很复杂,如果我有很多的提交,你有一个更好的解决办法? 谢谢。
米尔德里德
那么,当你做第二次合并,你总是可以使用'--squash'来避免创建提交,然后使用'git commit --amend'来修改以前的合并。 – Mildred 2009-11-12 22:42:56
这不起作用,它不会保存您在合并中提交的分支的新版本 – Mildred 2009-11-13 10:59:48