git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Automatically identifying the "split" point of a merged branch.
@ 2011-07-31  0:54 Conrad Irwin
  2011-07-31  5:53 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Conrad Irwin @ 2011-07-31  0:54 UTC (permalink / raw)
  To: git

Hello Gitters,

I wonder if I might pick your brains on the best way to handle a
situation I found myself in recently:

We have an integration branch, and a master branch, and a topic branch
that was based on the integration branch. Graphically:

A-o-o-o-o-o-o-o-o-o-E-(master)
 \
  o-o-B-o-o-o-o-M-o-o(integration)
       \       /
        C-o-o-D (topic)

I wanted to introduce this branch onto master to end up with:

A-o-o-o-o-o-o-o-o-o-E-----------N (master)
 \                   \         /
  \                   C'-o-o-D' (topic-rebased)
   \
    o-o-B-o-o-o-o-M-o-o(integration)
         \       /
          C-o-o-D (topic)

(ASCII art reproduced at http://dpaste.org/GUmM/ lest it be munged)

While it's easy to create comit N once I have commit D' (with git
merge --no-ff), I found that it's not at all easy to work out where
commit B is in order to do do a rebase --onto master B.

My usual approach would be to try and use git merge-base, but because
the topic branch is already merged into the integration branch, that
doesn't give useful output.

Is there a good way around this?

Conrad

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Automatically identifying the "split" point of a merged branch.
  2011-07-31  0:54 Automatically identifying the "split" point of a merged branch Conrad Irwin
@ 2011-07-31  5:53 ` Jeff King
  2011-07-31  6:08   ` Conrad Irwin
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2011-07-31  5:53 UTC (permalink / raw)
  To: Conrad Irwin; +Cc: git

On Sat, Jul 30, 2011 at 05:54:59PM -0700, Conrad Irwin wrote:

> I wanted to introduce this branch onto master to end up with:
> 
> A-o-o-o-o-o-o-o-o-o-E-----------N (master)
>  \                   \         /
>   \                   C'-o-o-D' (topic-rebased)
>    \
>     o-o-B-o-o-o-o-M-o-o(integration)
>          \       /
>           C-o-o-D (topic)
> 
> (ASCII art reproduced at http://dpaste.org/GUmM/ lest it be munged)
> 
> While it's easy to create comit N once I have commit D' (with git
> merge --no-ff), I found that it's not at all easy to work out where
> commit B is in order to do do a rebase --onto master B.

If you know M, then B is the merge-base of M^1 and M^2 (i.e., the
parents of M). If you don't know M, but do know D, you can find it by
walking backwards from "integration" until you find a merge commit with
D as its second parent (e.g., by grepping "rev-list --parents").

Make sense?

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Automatically identifying the "split" point of a merged branch.
  2011-07-31  5:53 ` Jeff King
@ 2011-07-31  6:08   ` Conrad Irwin
  0 siblings, 0 replies; 3+ messages in thread
From: Conrad Irwin @ 2011-07-31  6:08 UTC (permalink / raw)
  To: Jeff King; +Cc: git

On Sat, Jul 30, 2011 at 10:53 PM, Jeff King <peff@peff.net> wrote:
> On Sat, Jul 30, 2011 at 05:54:59PM -0700, Conrad Irwin wrote:
>
> If you know M, then B is the merge-base of M^1 and M^2 (i.e., the
> parents of M). If you don't know M, but do know D, you can find it by
> walking backwards from "integration" until you find a merge commit with
> D as its second parent (e.g., by grepping "rev-list --parents").
>
> Make sense?

Yup. git rev-list was definitely the tool I was missing, thank you :).

Conrad

merge=$(git rev-list --parents integration |\
                 grep " $(git rev-parse topic)" | cut -d' ' -f 1)
split=$(git merge-base $merge^ $merge^2)
git rebase --onto master $split
git checkout master
git merge --no-ff topic

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-07-31  6:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-31  0:54 Automatically identifying the "split" point of a merged branch Conrad Irwin
2011-07-31  5:53 ` Jeff King
2011-07-31  6:08   ` Conrad Irwin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).