如何挤压实际上在合并提交之前的两个提交? [英] How to squash two commits which are actually before a merge commit?

查看:125
本文介绍了如何挤压实际上在合并提交之前的两个提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设以下历史记录:

  X  -  Y  -  M  -  Z < - 特征
/ /
A - B - C - D < - master

我想修改历史记录以修正X和Y合并为一次提交。所以我希望历史看起来像这样:

  X' -  M'Z'< - 特征
/ /
A - B - C - D < - master

远远失败。大多数情况下,在转换期间会有冲突。也许rebase是不是正确的方式来实现这一点?



我明白(没有知道合并之前的有效情况没有真正改变)重新申请合并从主人到功能(M)导致了我在第一个地方解决的相同冲突。命令'rerere'可能是解决这个问题的一个选择,但据了解,这只有在'rerere'也被激活时才有可能。

但是在这种情况下,X-Y与X'具有相同的变更集。为什么git不够聪明只是重新申请M ?.如果我只是在一个提交X'中压缩X和Y,原始解析的更改(存储在M中)应该再次成为M'的正确内容。我怎么才能告诉git只是拿M的老内容来构建M'?解决方案

echo`git rev-parse YA`> .git / info / grafts
git filter-branch - --all
rm .git / info / grafts

过滤分支文档



移植物是回购本地血统覆盖。任何看到祖先的git都会看到嫁接的祖先,特别是重写提交的东西,并将它烘焙到重写的提交中。



过滤器是shell脚本片段,如果你想提供一个新的提交消息,你可以例如

  git filter-branch --msg-filter =
[\ $ commit =`git rev-parse Y`]&& cat<& 3 || cat - --all 3<< EOD
您的新提交邮件主题

您的新提交邮件正文
...
EOD


assume the following history:

   X - Y - M - Z   <- feature
 /        /
A - B - C - D      <- master

I want to rewrite history to fixup X and Y into a single commit. So i want the history look like this:

    X' -   M'- Z'  <- feature
 /        /
A - B - C - D      <- master

All of my attempts so far failed. Most of the time there are conflicts during the rebase. Maybe rebase is not the right way to achieve this?

I understand that (without the knowledge that the effective situation just before the merge hasn't really changed) reapplying the merge from master to feature (M) lead to the same conflicts that i solved in the frist place. The command 'rerere' could be an option to solve this, but as far is a know this is only possible if 'rerere' had been activated also in the first place.

But in this case X - Y do have the same changeset as X'. Why is git not clever enough to just reapply M?. If i just squash X and Y in a single commit X', the original resolved changes (which are stored in M) should again be the correct content for M'. How can i tell git to just take the old content of M to build M' ?

解决方案

echo `git rev-parse Y A` >.git/info/grafts
git filter-branch -- --all
rm .git/info/grafts

filter-branch docs

grafts are repo-local ancestry overrides. Anything in git that sees ancestry sees the grafted ancestry, in particular things that rewrite commits see it and so bake it into the rewritten commits.

The filters are shell script fragments, if you want to supply a new commit message you can e.g.

git filter-branch --msg-filter="
        [ \$commit = `git rev-parse Y` ] && cat <&3 || cat" -- --all 3<<EOD
your new commit message subject

your new commit message body here
...
EOD

这篇关于如何挤压实际上在合并提交之前的两个提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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