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

Re: How to pull a single changeset from a child branch into a parent branch?

From
Junio C Hamano <junkio@cox.net>
Date
Feb 10, 2006, 05:01 UTC
Message-ID
<7vzmkzyfhh.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<43EC10AA.1040800@candelatech.com>
Ben Greear <greearb@candelatech.com> writes:
Show 5 quoted lines
> I have a linux-2.6 repo with two branches off of 2.6.13.
>
> One branch (ben_v13) has just my own changes.
> A second branch (work_v13) has the 2.6.13.5 patch, and I've also pulled
> ben_v13 into it.
                     "2.6.13.5"
         o---o---o---o
        /             \ "work_v13"
    ---o "2.6.13"  .---*
        \         /
         o---o---o
                 "ben_v13"
	'o' are commits, '*' is a merge.
> Now, I made a small change to work_v13,
                     "2.6.13.5"
         o---o---o---o
        /             \   "work_v13"
    ---o "2.6.13"  .---*---x
        \         /        (new change)
         o---o---o
                 "ben_v13"
> ... and I'd like to pull only
> that changeset into ben_v13.  Is there a way to do that w/out
> having to export and apply a patch?
I would have done things differently.

It is generally a good idea if a change is applicable to more than one branches, and these branches have merge relationship between them (work_v13 merges from ben_v13, which has already happened), then to apply that change to the oldest branch and pull the branch to the new one. In other words, if you made the change to 2.6.13 based one, you could have pulled that into 2.6.13.5 based one.

                     "2.6.13.5"
         o---o---o---o
        /             \   "work_v13"
    ---o "2.6.13"  .---*
        \         /
         o---o---o---x
                      "ben_v13"
                   (new change)
    [Commit what is applicable to both in older branch]
                     "2.6.13.5"
         o---o---o---o
        /             \   "work_v13"
    ---o "2.6.13"  .---*--*
        \         /      /
         o---o---o---x---'
                      "ben_v13" 
                   (new change)
    [And then merge that to the derived one]

Assuming that correcting the situation like this is not an option, you could check "git cherry-pick". It lets you create something like this:

                     "2.6.13.5"
         o---o---o---o
        /             \   "work_v13"
    ---o "2.6.13"  .---*---x
        \         /
         o---o---o---------x'
                 "ben_v13" (equivalent of 'x' commit)
The command sequence to do this is:
	$ git checkout ben_v13
        $ git cherry-pick work_v13
Previous: Ben GreearNext: Ben Greear
Message 2 of 3 in “How to pull a single changeset from a child branch into a parent branch?”
  1. Ben GreearFeb 10, 2006
  2. Junio C HamanoFeb 10, 2006
  3. Ben GreearFeb 10, 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.