threads / discuss / 44798

Rebasing multiple branches at once

Subject: Rebasing multiple branches at once

## tl;dr

4 messages between Dec 31, 2016 and Jan 2, 2017.

replies: 3people: 4as markdown or json

Mike Hommey· Dec 31, 2016, 08:14 UTC · lore
Hi,

I've had this kind of things to do more than once, and had to do it a lot today, so I figured it would be worth discussing whether git-rebase should be enhanced to support this, or if this should go in a separate tool or whatever.

So here is what I'm trying to do in a not-too painful way:
I'm starting with something like this:
A---B---C---D---E
            \---F

where A is master, and E and F are two local topics with a common set of things on top of master.

The next thing that happens is that master is updated, and I want to rebase both topics on top of the new master.

So I now have:
A---G
\---B---C---D---E
            \---F

If I do the dumb thing, which is to do `git rebase master E` and `git rebase master F`, I end up with:

A---G---B'---C'---D'---E'
    \---B"---C"---D"---F'
That is, I just lost the fast that E and F had common history.

I could go with `git rebase master E` followed by `git rebase --onto D' D F` but that's cumbersome, especially when you have more than 2 topics, not necessarily diverging at the same point (e.g. I might have another topic that diverges at C)

So, what I end up doing is something like:
- git co -b merge E
- git merge --strategy ours F (and any other topic I might want to
  rebase)
- git rebase master --preserve-merges

If everything goes fine, then I can `git update-ref` the topics to each parent of the merge branch.

But, usually, since rebase --preserve-merges redoes merges with the default strategy, I end up with conflicts, and instead of trying to figure stuff out, I just pick the rewritten sha1s from .git/rebase-merge/rewritten/* to update the refs.

It is my understanding that the --strategy option to git-rebase is used for the rebase itself, so I'm not sure there's a way to tell rebase to use a specific strategy for the preserved merges only.

Anyways, it /seems/ like just allowing multiple branches on the git rebase command line and make this work would improve things significantly. The question then, is how would that interact with other options (I'm thinking e.g. -i, but -i already has a problem with --preserve-merges). But it does seem like it would be a worthwhile improvement.

What do you think?
Mike
Junio C Hamano· Jan 1, 2017, 02:40 UTC · re: Mike Hommey · lore

Re: Rebasing multiple branches at once

Mike Hommey <mh@glandium.org> writes:
Show 12 quoted lines
> So I now have:
>
> A---G
> \---B---C---D---E
>             \---F
>
> If I do the dumb thing, which is to do `git rebase master E` and `git
> rebase master F`, I end up with:
>
> A---G---B'---C'---D'---E'
>     \---B"---C"---D"---F'
>

What people seem to do is to teach the branch that ends with F that its upstream is the local branch that ends with E, so that they can be lazy when rebasing a branch that knows its upstream. I suspect that you would end up with

A---G---B'--C'--D'--E'--F'

instead if it is done naively, but if you really care that the branch that ends with F does not have E, you presumably want to have the branch that ends at D its own identity, so

 (1) 'master' or whatever that used to end at A and now its tip is
     at G;
 (2) the branch that ends at D whose upstream is 'master';
 (3) the branch that ends at E whose upstream is (2); and
 (4) the branch that ends at F whose upstream is (2).

I personally do not do that, though, because you'd need to remember the order in which these three branches must be rebased (i.e. (2) must be done first before rebasing (3) and (4) in any order).

Jeff King· Jan 2, 2017, 06:42 UTC · re: Junio C Hamano · lore

Re: Rebasing multiple branches at once

On Sat, Dec 31, 2016 at 06:40:33PM -0800, Junio C Hamano wrote:
Show 23 quoted lines
> What people seem to do is to teach the branch that ends with F that
> its upstream is the local branch that ends with E, so that they can
> be lazy when rebasing a branch that knows its upstream.  I suspect
> that you would end up with
> 
> A---G---B'--C'--D'--E'--F'
> 
> instead if it is done naively, but if you really care that the
> branch that ends with F does not have E, you presumably want to have
> the branch that ends at D its own identity, so
> 
>  (1) 'master' or whatever that used to end at A and now its tip is
>      at G;
> 
>  (2) the branch that ends at D whose upstream is 'master';
> 
>  (3) the branch that ends at E whose upstream is (2); and
> 
>  (4) the branch that ends at F whose upstream is (2).
> 
> I personally do not do that, though, because you'd need to remember
> the order in which these three branches must be rebased (i.e. (2)
> must be done first before rebasing (3) and (4) in any order).

I do occasionally have dependent topics, and use a topological sort to order my rebases, which solves the problem. The code I use is in:

  https://github.com/peff/git/blob/meta/rebase
-Peff
Johannes Sixt· Jan 1, 2017, 08:42 UTC · re: Mike Hommey · lore

Re: Rebasing multiple branches at once

Am 31.12.2016 um 09:14 schrieb Mike Hommey:
Show 32 quoted lines
> Hi,
>
> I've had this kind of things to do more than once, and had to do it a
> lot today, so I figured it would be worth discussing whether git-rebase
> should be enhanced to support this, or if this should go in a separate
> tool or whatever.
>
> So here is what I'm trying to do in a not-too painful way:
>
> I'm starting with something like this:
> A---B---C---D---E
>             \---F
>
> where A is master, and E and F are two local topics with a common set of
> things on top of master.
>
> The next thing that happens is that master is updated, and I want to
> rebase both topics on top of the new master.
>
> So I now have:
>
> A---G
> \---B---C---D---E
>             \---F
>
> If I do the dumb thing, which is to do `git rebase master E` and `git
> rebase master F`, I end up with:
>
> A---G---B'---C'---D'---E'
>     \---B"---C"---D"---F'
>
> That is, I just lost the fast that E and F had common history.
Git garden shears, perhaps?
https://public-inbox.org/git/alpine.DEB.2.20.1609111027330.129229@virtualbox/
-- Hannes

← back to recent threads