git rebase interactive:squash merge commits together [英] git rebase interactive: squash merge commits together

查看:180
本文介绍了git rebase interactive:squash merge commits together的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的资料库看起来像:

  X --- Y --------- M1 -------- M2(my-feature)
/ / /
/ / /
a --- b --- c --- d --- e --- f(stable)

也就是说,我有一个最近被合并过两次的 my-feature 分支,没有真正的提交。我不只是想重新绑定 my-feature 分支,因为它是它自己发布的分支,我只是想将最后两个合并提交合并为一个(还没有发布那些提交)

$ $ p $ code X --- Y ---- M(my-feature)
/ /
/ /
a --- ... - f(stable)

我试过:

  git rebase -p -i M1 ^ 



但是我得到了:

 拒绝挤压合并:M2 

我最后做的是:

  git checkout my-feature 
git reset --soft HEAD ^#删除最后一次提交(M2),但将更改保留在索引
中git commit - m toto#重做提交M2,这次它不是合并提交
git rebase -p -i M1 ^#做rebase和压缩最后一次提交
git diff M2 HEAD#测试提交是同样的

现在,th新的合并提交不再被视为合并提交(它只保留第一个父代)。所以:

  git reset --soft HEAD ^#准备修改提交
git stash#put away索引
git合并-s我们的--no-commit stable#重新生成合并信​​息(第二个父)
git stash apply#获取索引并返回真正的合并
git commit - a#提交您的合并
git diff M2 HEAD#测试您再次提交了相同的提交

但如果我有很多提交,这会变得复杂,你有更好的解决方案吗?
Thanks。



Mildred

解决方案

老话题,但我只是在寻找类似信息时碰到了它。

类似于 Subtree章鱼合并对这类问题是一个很好的解决方案:

  git checkout my-feature 
git reset --soft Y
git rev-parse f> .git / MERGE_HEAD
git commit

这将取指标作为提示我的功能,并使用它来创建一个新的承诺Y,与'f'作为第二个父母。结果与您从未执行过M1相同,但直接进入M2。

I wanted to have a simple solution to squash two merge commits together during an interactive rebase.

My repository looks like:

   X --- Y --------- M1 -------- M2 (my-feature)
  /                 /           /
 /                 /           /
a --- b --- c --- d --- e --- f (stable)

That is, I have a my-feature branch that has been merged twice recently, with no real commits in between. I don't just want to rebase the my-feature branch since it is a published branch of its own, I just want to squash together the last two merge commits into one (haven't published those commits yet)

   X --- Y ---- M (my-feature)
  /            /
 /            /
a --- ... -- f (stable)

I tried:

git rebase -p -i M1^

But I got:

Refusing to squash a merge: M2

What I finally did is:

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

Now, the new merge commit is not considered a merge commit anymore (it only kept the first parent). So:

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

But this can get complicated if I have many commits, do you have a better solution ? Thanks.

Mildred

解决方案

This is an old topic, but I just ran across it while looking for similar information.

A trick similar to the one described in Subtree octopus merge is a really good solution to this type of problem:

git checkout my-feature
git reset --soft Y
git rev-parse f > .git/MERGE_HEAD
git commit

That will take the index as it exists at the tip of my-feature, and use it to create a new commit off of Y, with 'f' as a second parent. The result is the same as if you'd never performed M1, but gone straight to performing M2.

这篇关于git rebase interactive:squash merge commits together的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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