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

Re: Apply commits from one branch to another branch (tree structure is different)

From
JTJagan Teki <jagannadh.teki@gmail.com>
Date
Mar 14, 2014, 20:57 UTC
Message-ID
<CAD6G_RTzbJGc10doV_ZbC5bd=Zpr6rPbNXni+Yo7cxD38DCLMQ@mail.gmail.com>
In-Reply-To
<CADgNjan2SQXXfYfMP0sk5tqY_=c68=y0dfANF_KFaPQpzNG3yA@mail.gmail.com>
On Sat, Mar 15, 2014 at 2:07 AM, Andrew Wong <andrew.kw.w@gmail.com> wrote:
Show 38 quoted lines
> On Fri, Mar 14, 2014 at 4:01 PM, Jagan Teki <jagannadh.teki@gmail.com> wrote:
>> On Sat, Mar 15, 2014 at 12:48 AM, Andrew Wong <andrew.kw.w@gmail.com> wrote:
>>> On Fri, Mar 14, 2014 at 1:39 PM, Jagan Teki <jagannadh.teki@gmail.com> wrote:
>>>> Suppose developer send 10 patches on branch1 where are changes in terms
>>>> of <dir>_<version>/ then I need to apply on my local repo branch1, till now
>>>> is fine then I need to apply same 10 patches on to my branch2 where source
>>>> tree <dir> which is quite question here how can I do.
>>>
>>> You might be able to use the subtree option in recursive merge. Try
>>> something like:
>>>
>>>     git cherry-pick -X subtree=foo <commit>
>>>
>>> This tells git to apply the changes to the "foo" directory in your
>>> current branch (branch2).
>>
>> How do I do this?
>>
>> Suppose I'm in branch1 with two commits on foo_v2 and I need to apply them
>> on branch2 where in foo.
>
> Since this uses cherry-pick, the changes that you want to apply have
> to be on branch1 already.
>
> Let's say your branch1 looks like:
>     --A--B--C--D
> and branch2 looks like:
>     --1--2--3--4
>
> And you want to apply commits B and C on branch2, but they modify
> "foo_v1/" on branch1. You can tell git to apply the commits onto the
> directory "foo/" on branch2:
>     git checkout branch2    # make sure you're on branch2
>     git cherry-pick -X subtree=foo B C    # pick the commits
>
> If there's no conflict, the commits should apply cleanly, and your
> branch2 would become like:
>     --1--2--3--4--B'--C'

I created two commits on foo_v2 when I move branch2 and did cherry-pick it shows below:

Mr.J> git cherry-pick -X subtree=foo cc70089614de16b46c08f32ea61c972fea2132ce 14e9c9b20e3bf914f6a38ec720896b3d67f94c90 error: could not apply cc70089... AAAAAAAAAAAAAAAAA hint: after resolving the conflicts, mark the corrected paths hint: with 'git add <paths>' or 'git rm <paths>' hint: and commit the result with 'git commit' Mr.J> ls foo Mr.J> gs # On branch branch2 # Unmerged paths: # (use "git add/rm <file>..." as appropriate to mark resolution) # # deleted by us: foo/foo_v2/test.txt # no changes added to commit (use "git add" and/or "git commit -a")

thanks!
-- 
Jagan.
Previous: Andrew WongNext: Andrew Wong
Message 7 of 9 in “Apply commits from one branch to another branch (tree structure is different)”
  1. Jagan TekiMar 14, 2014
  2. Jagan TekiMar 14, 2014
  3. Brandon McCaigMar 18, 2014
  4. Andrew WongMar 14, 2014
  5. Jagan TekiMar 14, 2014
  6. Andrew WongMar 14, 2014
  7. Jagan TekiMar 14, 2014
  8. Andrew WongMar 14, 2014
  9. Brandon McCaigMar 18, 2014

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.