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

Re: git rebase behaviour changed?

From
Junio C Hamano <junkio@cox.net>
Date
Jan 17, 2006, 08:11 UTC
Message-ID
<7v8xtfclyx.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<46a038f90601162252y7e2d9227p4eb4091b653d5c6d@mail.gmail.com>
Martin Langhoff <martin.langhoff@gmail.com> writes:
> Now, I have realised that a simple mistake (merging from origin in you
> scenario) would lead git-rebase to discard earlier patches during the
> rebase. If you had a single commit *after* the merge, git-rebase would
> have rebased that single patch, and dropped earlier patches.
It may not necessarily be a mistake.
Show 6 quoted lines
> git-rebase should refuse to run in the above scenario. Is there a
> straightforward way to ask if the merge base is "shared"?
>
> <thinking>
>...
> </thinking>

Sorry I am always slow but I am a bit slower than I usually am tonight, and do not understand this part without an illustration:

        master    1---2---3---4---5---A
                 /           /
	origin  0---6---7---B
                A = master head
                B = origin head == merge base
	rev-list B..A = 1 2 3 4 5
        rev-list A..B = 6 7

The first rev-list is "what we have but they do not". They are the candidates to be fed upstream. The latter is "what they have but we do not". Potentially some of them are commit that represent patches we submitted earlier upstream.

Among the first list of commit, there is #4 which is a merge. So we reject. Is that what you meant? Which makes sense in this picture (but I am a bit tired and maybe this may not apply in a different picture).

By the way, the longer I think about this, the more I agree with the conclusion of the earlier thread: "if you rebase, do not merge; if you merge, do not rebase". It is really about picking the right workflow.

Let's say you submitted #1, #2, #3 earlier, and #3 was accepted upstream and came back as #7, and let's further assume that we are lucky enough that patch-id gives the same answer for "diff-tree #2" and "diff-tree #7". So the set of commits left are #1, #3, and #5 (#4 is just a merge so we will not re-apply).

Now, what is the shape of the final "rebased" ancestry graph we would want?

        master                1'--3'--5'--A'
                             /
	origin  0---6---7---B

If this is what we want, why did we make #4 merge in the first place, I wonder. If the workflow is based on rebase [*1*], instead of making a merge at #4, the developer *should* have done fetch and rebase, not merge:

        master    1---2---3
                 /
	origin  0---6---7---B
        ==>
        master                1'--3'
                             /
	origin  0---6---7---B

This would have been easier to manage at the point we discovered #6, #7, and #B, than creating #4 merge only to discard it later.

And #5 and #A can be built on top of #3'.
        master                1'--3'--5---A
                             /
	origin  0---6---7---B
[Footnote]

*1* That is certainly easier to manage for an individual developer than a merge based workflow. I know it because I operated that way for a long time back when Linus was managing git)

Previous: Martin LanghoffNext: Martin Langhoff
Message 6 of 9 in “git rebase behaviour changed?”
  1. Mike McCormackJan 17, 2006
  2. Junio C HamanoJan 17, 2006
  3. Mike McCormackJan 17, 2006
  4. Junio C HamanoJan 17, 2006
  5. Martin LanghoffJan 17, 2006
  6. Junio C HamanoJan 17, 2006
  7. Martin LanghoffJan 17, 2006
  8. Junio C HamanoJan 17, 2006
  9. Junio C HamanoJan 17, 2006

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.