Thread (9 messages) 9 messages, 3 authors, 2016-06-15

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

From: Andrew Wong <hidden>
Date: 2016-06-15 23:00:19

On Fri, Mar 14, 2014 at 4:01 PM, Jagan Teki [off-list ref] wrote:
On Sat, Mar 15, 2014 at 12:48 AM, Andrew Wong [off-list ref] wrote:
quoted
On Fri, Mar 14, 2014 at 1:39 PM, Jagan Teki [off-list ref] wrote:
quoted
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'
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help