threads / discuss / 44503

Rebasing cascading topic trees

Subject: Rebasing cascading topic trees

## tl;dr

5 messages between Nov 16, 2016 and Nov 17, 2016.

replies: 4people: 3as markdown or json

Norbert Kiesel· Nov 16, 2016, 23:39 UTC · lore

I currently have a situation with cascading topic branches that I need to rebase regularly. In the picture below, I want to rebase the tree starting with `E` to be rebased onto master (my actually cascade is 4 branches deep).

A--B--C--D (master)
   \
    E--F (topic1)
       \
        G--H (topic2)
After running `git rebase --onto master master topic1`, I end up with
A--B--C--D (master)
   |     \
   \      E'--F' (topic1)
    E--F
       \
        G--H (topic2)

I then need to also run `git rebase --onto topic1 F topic2` to arrive at the desired

A--B--C--D (master)
   |     \
   \      E'--F' (topic1)
    E--F      \
       |       G'--H' (topic2)
       \
        G--H

Problem here is that I don't have a nice symbolic name for `F` anymore after the first rebase. Rebasing `topic2` first is not really possible, because I do not have a new graft-point yet. I currently write down `F` ahead of time (or use `reflog` if I forgot) `F`, but I wonder if there is a better solution.

Junio C Hamano· Nov 16, 2016, 23:44 UTC · re: Norbert Kiesel · lore

Re: Rebasing cascading topic trees

Norbert Kiesel <nkiesel@gmail.com> writes:
Show 34 quoted lines
> I currently have a situation with cascading topic branches that I need to rebase
> regularly.  In the picture below, I want to rebase the tree starting with `E` to
> be rebased onto master (my actually cascade is 4 branches deep).
>
> A--B--C--D (master)
>    \
>     E--F (topic1)
>        \
>         G--H (topic2)
>
> After running `git rebase --onto master master topic1`, I end up with
>
> A--B--C--D (master)
>    |     \
>    \      E'--F' (topic1)
>     E--F
>        \
>         G--H (topic2)
>
> I then need to also run `git rebase --onto topic1 F topic2` to arrive at the
> desired
>
> A--B--C--D (master)
>    |     \
>    \      E'--F' (topic1)
>     E--F      \
>        |       G'--H' (topic2)
>        \
>         G--H
>
> Problem here is that I don't have a nice symbolic name for `F` anymore after the
> first rebase. Rebasing `topic2` first is not really possible, because I do not
> have a new graft-point yet.  I currently write down `F` ahead of time (or use
> `reflog` if I forgot) `F`, but I wonder if there is a better solution.

Doesn't topic1@{1} point at "F" after the rebase of the topic1 finishes?

Norbert Kiesel· Nov 17, 2016, 00:12 UTC · re: Junio C Hamano · lore

Re: Rebasing cascading topic trees

Yes, `git rebase --onto topic1 topic1@{1} topic2` is the answer!
Thanks so much, learned something new today.
On Wed, Nov 16, 2016 at 3:44 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 40 quoted lines
> Norbert Kiesel <nkiesel@gmail.com> writes:
>
>> I currently have a situation with cascading topic branches that I need to rebase
>> regularly.  In the picture below, I want to rebase the tree starting with `E` to
>> be rebased onto master (my actually cascade is 4 branches deep).
>>
>> A--B--C--D (master)
>>    \
>>     E--F (topic1)
>>        \
>>         G--H (topic2)
>>
>> After running `git rebase --onto master master topic1`, I end up with
>>
>> A--B--C--D (master)
>>    |     \
>>    \      E'--F' (topic1)
>>     E--F
>>        \
>>         G--H (topic2)
>>
>> I then need to also run `git rebase --onto topic1 F topic2` to arrive at the
>> desired
>>
>> A--B--C--D (master)
>>    |     \
>>    \      E'--F' (topic1)
>>     E--F      \
>>        |       G'--H' (topic2)
>>        \
>>         G--H
>>
>> Problem here is that I don't have a nice symbolic name for `F` anymore after the
>> first rebase. Rebasing `topic2` first is not really possible, because I do not
>> have a new graft-point yet.  I currently write down `F` ahead of time (or use
>> `reflog` if I forgot) `F`, but I wonder if there is a better solution.
>
> Doesn't topic1@{1} point at "F" after the rebase of the topic1
> finishes?
>
Jeff King· Nov 17, 2016, 01:45 UTC · re: Norbert Kiesel · lore

Re: Rebasing cascading topic trees

On Wed, Nov 16, 2016 at 04:12:20PM -0800, Norbert Kiesel wrote:
> Yes, `git rebase --onto topic1 topic1@{1} topic2` is the answer!

See also the `--fork-point` option, which (I think) should do this for you (and is the default if "topic1" is the configured upstream for topic2 and you just run "git rebase").

-Peff
Norbert Kiesel· Nov 17, 2016, 03:21 UTC · re: Jeff King · lore

Re: Rebasing cascading topic trees

More things I learned!

So there are (at least) 2 possible approaches: using history, or using local tracking branches. The latter looks actually nicer to me, with the exception that if asks for a `git pull`. Using `git pull --rebase` actually also ends up with the same tree, but I like the rebase better.

The following 2 scripts show the 2 approaches. Only difference is in the creation of topic/b and the last rebase command.

# History mkdir topic; cd topic git init date > a; git add a; git commit -m a date > b; git add b; git commit -m b git branch -b topic/a git checkout -b topic1 date > c; git add c; git commit -m c date > d; git add d; git commit -m d git checkout -b topic2 date > e; git add e; git commit -m e date > f; git add f; git commit -m f git checkout master date > g; git add g; git commit -m g echo "before rebase"; git log --oneline --graph --all git rebase master topic1 echo "after rebase of topic1"; git log --oneline --graph --all git rebase --onto=topic1 topic1@{1} topic2 echo "after rebase of topic2"; git log --oneline --graph --all

# Tracking mkdir topic; cd topic git init date > a; git add a; git commit -m a date > b; git add b; git commit -m b git branch -b topic/a git checkout -b topic1 date > c; git add c; git commit -m c date > d; git add d; git commit -m d git checkout --track topic1 -b topic2 date > e; git add e; git commit -m e date > f; git add f; git commit -m f git checkout master date > g; git add g; git commit -m g echo "before rebase"; git log --oneline --graph --all git rebase master topic1 echo "after rebase of topic1"; git log --oneline --graph --all git rebase --onto=topic1 master topic2 echo "after rebase of topic2"; git log --oneline --graph --all

On Wed, Nov 16, 2016 at 5:45 PM, Jeff King <peff@peff.net> wrote:
Show 9 quoted lines
> On Wed, Nov 16, 2016 at 04:12:20PM -0800, Norbert Kiesel wrote:
>
>> Yes, `git rebase --onto topic1 topic1@{1} topic2` is the answer!
>
> See also the `--fork-point` option, which (I think) should do this for
> you (and is the default if "topic1" is the configured upstream for
> topic2 and you just run "git rebase").
>
> -Peff

← back to recent threads