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

Rebasing a branch that contains merges

From
APAndy Parkins <andyparkins@gmail.com>
Date
Feb 19, 2007, 09:12 UTC
Message-ID
<200702190912.24067.andyparkins@gmail.com>
Hello,

I've done some little experiments with rebasing a branch with merges on it. I wanted to check that what I found is what is intended.

I made a repository like this:
 * -- * -- * (master)
      |\
      | A (branch1) -- M (merge)
       \              /
        B (branch2) --
It's a horribly unfair thing to do, but while on merge I did
 git rebase master
I had been hoping that both branches would rebase, but only one did.  I got:
 * -- * -- * (master) -- B -- M (merge)
      |\
      | A (branch1)
       \              
        B (branch2)

"M" effectively now contains all of branch1's changes. If I hadn't referenced the merge head separately from the two branch heads, all the history in branch1 would now be represented by "M".

I don't think this is the right result.  Either
 * git should refuse to rebase because it would lose history
 * git should rebase both branches
The ideal result (perhaps unrealisticly) would have been
 * -- * -- * (master)
           |\
           | A (branch1) -- M (merge)
            \              /
             B (branch2) --

This is an unreasonable thing to expect a version control system to be able to do - it's a nasty, complicated wish. git is its own worst enemy for things like this; it's getting to be so good at nasty unreasonable things that they don't seem like fantasy-land wishes.

A perfectly valid answer is "don't be so ridiculous Andy, go away". :-)
Andy
-- 
Dr Andy Parkins, M Eng (hons), MIEE
andyparkins@gmail.com
Next: Junio C Hamano
Message 1 of 4 in “Rebasing a branch that contains merges”
  1. Andy ParkinsFeb 19, 2007
  2. Junio C HamanoFeb 19, 2007
  3. Andy ParkinsFeb 19, 2007
  4. A.J. RossiniFeb 19, 2007

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.