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

Re: Commiting changes onto more than one branch

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 25, 2009, 18:58 UTC
Message-ID
<7vaayazb2a.fsf@alter.siamese.dyndns.org>
In-Reply-To
<6b4a562b0911250847x59116687iba1d1640ca6c3887@mail.gmail.com>
Mike Jarmy <mjarmy@gmail.com> writes:
Show 6 quoted lines
> I guess I didn't explain it too well, I made it sound like v3, v4 and
> v5 were still more-or-less the same.  What I'm thinking about here is
> a case where we have switched to git a while back, and then done a lot
> of work on the various different branches, so that v3, v4 and v5 have
> diverged very far from each other.  In that case, we would never want
> to merge them together.

I take it to mean that even though v[345] have diverged, the area that the particular change you have in mind has to touch haven't changed since they forked. Otherwise you wouldn't be able to apply the same change to all of them in the same form and instead would be making the logically same change in physically different ways per branch, and you won't be asking this question.

        o--o--o--o--o--o--o--o v4
       /
    --o--x--x--x--x--x--x--x v3

If you implemented your change at the tip of v3 branch and merge the result to v4, you will pull _all_ of 'x' into v4 that may not be desirable if the branches diverged a lot, of course.

        o--o--o--o--o--o--o--o-------M v4
       /                            /
    --o--x--x--x--x--x--x--x       /
                            \     /
                             Y---Y your change(s) == v3
But nobody tells you to do this.
Instead, you can fork such a topic from the latest common.
        o--o--o--o--o--o--o--o v4
       /
    --o--x--x--x--x--x--x--x v3
       \
        Y---Y
            your change(s)
and merging this to v3 and v4 will have the desired effect.
        o--o--o--o--o--o--o--o---------M v4
       /                              /
    --o--x--x--x--x--x--x--x---M v3  /
       \                      /     /
        Y---Y----------------.-----.
            your change(s)

The merges will incorporate this particular change alone without dragging anything else. When you merge it to v4, none of the unrelated 'x' will be merged into it.

In general you shouldn't fork a topic from the _tip_ of the oldest branch, if the branches are not meant to be merged as a whole.

Of course, if this becomes cumbersome, you would adopt a better branch management to keep the numbers of 'x' that shouldn't be in later branches to the minimum.

Previous: Avery PennarunNext: Mike Jarmy
Message 5 of 12 in “Commiting changes onto more than one branch”
  1. Mike JarmyNov 25, 2009
  2. Eugene SajineNov 25, 2009
  3. Mike JarmyNov 25, 2009
  4. Avery PennarunNov 25, 2009
  5. Junio C HamanoNov 25, 2009
  6. Mike JarmyNov 25, 2009
  7. Daniel BarkalowNov 25, 2009
  8. Andreas SchwabNov 25, 2009
  9. Thomas RastNov 25, 2009
  10. Jakub NarebskiNov 25, 2009
  11. Mike JarmyNov 25, 2009
  12. Nicolas PitreNov 25, 2009

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.