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

Re: interactive rebase results across shared histories

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Feb 21, 2016, 19:08 UTC
Message-ID
<CAPig+cSxmWc_Guab0UoQbRMEkVLr-qhF=LCiVk10G5AdnTqnGA@mail.gmail.com>
In-Reply-To
<8737sm6kmk.fsf@gmail.com>
On Sun, Feb 21, 2016 at 12:25 PM, Seb <spluque@gmail.com> wrote:
Show 15 quoted lines
> The scenario is much simpler; imagine master has a longer history behind
> the point where the topic branch started:
>
>                 A---B---C topic
>                /
>   *---D---E---F---G master
>
> And we want to keep both branches separate (no desire to merge them for
> now), but we realize that, say, commits D and E should be
> squashed/fixup, so we do an interactive rebase.  Now, the problem is
> that if I do that from the topic branch, the results are not reflected
> in the master branch, even though these commits are certainly shared
> with master.  It seems counterintuitive that a part of history that is
> shared among branches can be independently manipulated/rewritten with
> rebase.  I must be missing something...

What you're probably missing is that you can't actually edit commits in Git. Instead, what you think of as "editing" actually creates a new commit with its own commit-ID, and the original commit still exists with its own commit-ID. Since Git commits are chained together by their commit-ID's, any commits pointing at the original commit-ID continue to point to that commit, and only commits rebased atop the new commit-ID of the "edited" commit point at it.

In your example, you're "editing" D and E, which creates new commits D' and E', so your resulting graph looks like this:

    D'---E'---A---B---C topic
   /
  *---D---E---F---G master

So, "master" and "topic" really are not sharing D and E (or D' and E'). You could "fix" this to match your intuition by rebasing F...G onto E' (see git-rebase --onto, for instance), which would give you this:

                  A---B---C topic
                 /
  *---D'---E'---F---G master

and then "master" and "topic" would really be sharing D' and E' as common history. (Of course, rebasing "master" or any branch may not be desirable if you've published it, so applicable warnings about rebasing apply.)

By the way, the problem isn't restricted to when you rebase "topic" (as your problem description implies). You'd see the same behavior if you'd rebased D and E in "master" to become D' and E'. "topic" would still have old D and E in its history, and not D' and E'.

Previous: SebNext: Seb
Message 4 of 13 in “interactive rebase results across shared histories”
  1. SebFeb 20, 2016
  2. Moritz NeebFeb 21, 2016
  3. SebFeb 21, 2016
  4. Eric SunshineFeb 21, 2016
  5. SebFeb 22, 2016
  6. DavidFeb 22, 2016
  7. SebFeb 23, 2016
  8. Moritz NeebFeb 23, 2016
  9. Kevin DaudtFeb 23, 2016
  10. SebFeb 23, 2016
  11. DavidFeb 26, 2016
  12. SebFeb 26, 2016
  13. Stepan KasalFeb 26, 2016

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.