git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] Documentation: new upstream rebase recovery section in git-rebase

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 13, 2008, 05:08 UTC
Message-ID
<7v8wtwk4yp.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<1221147525-5589-2-git-send-email-trast@student.ethz.ch>
Thomas Rast <trast@student.ethz.ch> writes:
Show 5 quoted lines
> +RECOVERING FROM UPSTREAM REBASE
> +-------------------------------
> +
> +This section briefly explains the problems that arise from rebasing or
> +rewriting published branches, and shows how to recover.

The largest issue of "The problem" is that the person who rebases causes this problem to others, _forcing_ his downstream to recover. This intro needs to make it clear the distinction between the person who rebases, who suffers is forced to recover as the consequence.

Show 13 quoted lines
> +    o---o---o---o---o  master
> +         \
> +          o---o---o---o---o  subsystem
> +                           \
> +                            *---*---*  topic
>...
> +If 'subsystem' is rebased against master, the following happens:
>...
> +    o---o---o---o---o  master
> +        |            \
> +        |             o'--o'--o'--o'--o'  subsystem
> +        \
> +         o---o---o---o---o---*---*---*  topic

Make the original upstream a bit longer in the "after" picture, explaining that "your upstream subsystem rebased on top of its own upstream after it gets updated", so that the part that are unchanged in two pictures are not drawn differently like you did above.

In other words, draw it like this. It is much easier to see what's changed and what's unchanged, if the part that hasn't changed stayed unchanged in the picture:

       o---o---o---o---o  master
            \
             o---o---o---o---o  subsystem
                              \
                               *---*---*  topic
       o---o---o---o---o---o---o---o  master
            \                       \ 
             o---o---o---o---o       o'--o'--o'--o'--o' subsystem
                              \
                               *---*---*  topic
Show 5 quoted lines
> +Note that while we have marked your own commits with a '*', there is
> +nothing that distinguishes them from the commits that previously were
> +on 'subsystem'.  Luckily, 'git-rebase' knows to skip commits that are
> +textually the same as commits in the upstream.  So if you say
> +(assuming you're on 'topic')

There is no luck involved in "git rebase" knowing how to do this -- this is by design.

But more importantly, at this point, there is a break in the flow of thought in this section. Step back and read what you wrote, pretending as if you are reading the section for the first time, and notice:

 * The readers were shown how the topology before and after the
   subsystem's rebase looked like;
 * The readers haven't been told what you are trying teach them now.  Yes,
   I know that you are going to tell them how to transplant their own
   commits on top of updated subsystem, but they don't know that yet;
 * Some of the readers may not even understand why it is a bad idea to
   keep building on top of the old subsystem without rebasing on top of
   the rebased subsystem at this point.

Only when the readers know that the objective is to transplant these three top commits, they would start appreciating the difficulty (i.e. you cannot tell the commits apart by looking at the topology alone) of rebase the reader has to do, and the smart (i.e. if you are lucky, the rebase your upstream did may have been a simple one) git-rebase uses to help them.

It would suffice to insert something like this before "Note that...".
        To continue working from here, you need to transplant your own
        commits (marked as '*') on top of the "subsystem", which is now
        rebased.
But see footnote below.
> +This becomes a ripple effect to anyone downstream of the first rebase:
> +anyone downstream from 'topic' now needs to rebase too, and so on.
This calls for a stronger wording than "needs to", perhaps "forced to".
> +Things get more complicated if your upstream used `git rebase
> +--interactive` (or `commit --amend` or `reset --hard HEAD^`).

I do not think this section is absolutely necessary. The upstream may have done a simple rebase, which may have conflicted with the changes in its own upstream.

Show 8 quoted lines
> +To fix this, you have to manually transplant your own part of the
> +history to the new branch head.  Looking at `git log`, you should be
> +able to determine that three commits on 'topic' are yours.  Again
> +assuming you are already on 'topic', you can do
> +------------
> +    git rebase --onto subsystem HEAD~3
> +------------
> +to put things right.

HEAD~3 would _work_, but it often is easier to visualize this (perhaps in your head, or in "gitk HEAD origin origin@{1}"):

       o---o---o---o---o---o---o---o  master
            \                       \ 
             o---o---o---o---o       o'--o'--o'--o'--o' subsystem
                              \
                               *---*---*  topic
and say:
    $ git rebase --onto subsystem subsystem@{1}

The reflog reference "1" may be larger depending on the number of times you fetched from them without rebasing, though.

[Footnote]

You did not cover why midstream rebase _forces_ downstream to rebase. If the leaf-level person did not know better, or did not care, starting from this topology:

       o---o---o---o---o---o---o---o  master
            \                       \ 
             o---o---o---o---o       o'--o'--o'--o'--o' subsystem
                              \
                               *---*---*  topic

the leaf person can keep building on top of the old topic, and later when the topic is mature, have subsystem merge the result. If the rebase the subsystem did was simple enough, the merge will be easy to resolve (both sides modifying the same way).

       o---o---o---o---o---o---o---o  master
            \                       \ 
             o---o---o---o---o       o'--o'--o'--o'--o'--M subsystem
                              \                         /
                               *---*---*---*---*---*---*

The problem is that the resulting history will keep two copies of the morally equivalent commits from the subsystem. You know that, and I know that, but the purpose of the document is to explain it to people who do not know it yet.

Previous: Marcus GriepNext: Thomas Rast
Message 22 of 29 in “Documentation: new upstream rebase recovery section in git-rebase”
  1. Documentation: new upstream rebase recovery section in git-rebaseThomas Rast, Sep 2, 2008
  2. Junio C HamanoSep 2, 2008
  3. Thomas RastSep 3, 2008
  4. 0/2 Documentation: new upstream rebase recovery section in git-rebaseThomas Rast, Sep 11, 2008
  5. 1/2 Documentation: new upstream rebase recovery section in git-rebaseThomas Rast, Sep 11, 2008
  6. 2/2 Documentation: Refer to git-rebase(1) to warn against rewritingThomas Rast, Sep 11, 2008
  7. Documentation: add manpage about workflowsThomas Rast, Sep 11, 2008
  8. Jakub NarebskiSep 11, 2008
  9. [RFH] Asciidoc non-example blocks [was: Re: [RFC PATCH] Documentation: add manpage about workflows]Thomas Rast, Sep 12, 2008
  10. Santi BéjarSep 20, 2008
  11. Dmitry PotapovSep 21, 2008
  12. Thomas RastSep 30, 2008
  13. Thomas RastSep 30, 2008
  14. Santi BéjarOct 1, 2008
  15. Documentation: add manpage about workflowsThomas Rast, Oct 9, 2008
  16. [Interdiff] [RFC PATCH v2] Documentation: add manpage about workflowsThomas Rast, Oct 9, 2008
  17. Junio C HamanoOct 9, 2008
  18. Documentation: add manpage about workflowsThomas Rast, Oct 19, 2008
  19. [Interdiff] [RFC PATCH v3] Documentation: add manpage about workflowsThomas Rast, Oct 19, 2008
  20. Junio C HamanoOct 19, 2008
  21. Marcus GriepSep 12, 2008
  22. Junio C HamanoSep 13, 2008
  23. 0/3 Documentation: rebase and workflowsThomas Rast, Sep 13, 2008
  24. 1/3 Documentation: new upstream rebase recovery section in git-rebaseThomas Rast, Sep 13, 2008
  25. 2/3 Documentation: Refer to git-rebase(1) to warn against rewritingThomas Rast, Sep 13, 2008
  26. 3/3 Documentation: add manpage about workflowsThomas Rast, Sep 13, 2008
  27. Interdiff: [3/3] Documentation: add manpage about workflowsThomas Rast, Sep 13, 2008
  28. Junio C HamanoSep 8, 2008
  29. Thomas RastSep 9, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.