具有合并子项的Git Rebase分支 [英] Git rebase branch with merged children

查看:107
本文介绍了具有合并子项的Git Rebase分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我面临一个问题.我的队友从主人那里创建了分支.他在此分支中开发了一个功能,然后在该子功能的分支中开发了两个子功能.最后,他对整个事情进行了两次重构.所以...

Today I faced with one problem. My teammate created branch from master. He developed one feature in this branch and after that developed two subfeatures in subfeature's branches. At last he did two refactoring commit of the entire thing. So...

     C--D    E--F             | subfeatures
    /    \  /    \
   B------M1------M2--G--H    | feature
  /
 A-------------------K        | master

通常,我们在不快进将功能分支合并到母版之前对其进行重新分类.但是,当然,此变基失败了.重新设置的功能分支看起来像:

Usually we rebase feature branches before no-fast-forward merge it into master. But of course this rebase fails. Rebased feature branch became looking like:

     B'--C'--D'--E'--F'--G'--H'
    /
A--K

当然是C&的指针. D弄错了,所以我也得到了两个子功能分支,它们从空中"生长.我知道如果子功能分支未合并到功能中,该如何解决,但是此时我感到困惑.我在重新建立基础的恢复分支中挑选了所有内容,然后又全部合并了.这是更简单的方法吗?

Of course pointers of C & D became wrong so I also get two subfeature branches growing 'from air'. I understand how to fix it if subfeature branches wasn't merged into feature, but at this time I was confused. I cherry-picked everything in rebased recovery branch and merged all again. Is here a easier way to do it?

推荐答案

请注意,您需要git1.7.6 +才能使git rebase --preserve-merges正常工作.

Note that you need a git1.7.6+ for git rebase --preserve-merges to work properly.

  • 一个rebase --preserve-merges --onto以前没有工作(" 不保留合并)
  • 一个rebase --preserve-merges在某些情况下存在问题:
    • a rebase --preserve-merges --onto didn't work before ("git rebase --preserve-merges --onto doesn't preserve merges")
    • a rebase --preserve-merges had issue in some instance:
      • see this thread, when both sides of the merge are replayed)
      • "Git: Rebasing Merge Commits " (post from Alexandru Pasca)

      长话短说:您刚刚完成了合并,并且有人先提交了一次提交,然后才可以提交.解决方案是让git知道您所做的合并.

      Long story short: You just completed a merge and somebody has pushed a commit before you were able to push yours. The solution is to make git aware of the merge you did.

      git rebase --preserve-merges <upstream>
      

      git rebase -p <upstream>
      

      但是有一个问题,如果您的合并中有您解决的冲突,那么它们将不会被重新设置基准的机器接受.
      而且您最终将再次解决冲突...至少在git版本1.7.5.4中就是这种情况

      But there's a problem, if your merge had conflicts that you solved they won't be picked up by the rebase machinery.
      And you will end up resolving the conflicts again ... at least this is the case with git version 1.7.5.4

      (这需要 git rerere )

      这篇关于具有合并子项的Git Rebase分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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