我想有一个简单的解决方案来在交互式 rebase 期间将两个合并提交压缩在一起。
我的存储库看起来像:
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
但是如果我有很多提交,这可能会变得复杂,你有更好的解决方案吗?谢谢。
米尔德里德