threads / discuss / 36157

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

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

## tl;dr

9 messages between Mar 14, 2014 and Mar 18, 2014.

replies: 8people: 3as markdown or json

Jagan Teki· Mar 14, 2014, 17:39 UTC · lore
Hi,

I have two branch in one repo that I need to maintain for 2 different deliveries. Say branch1 and branch2 in test.git repo.

test.git
- branch1
     foo_v1/text.txt
     foo_v2/text.txt
- branch2
     foo/text.txt

branch1 is developers branch all source looks version'ed manner and branch2 is superset for branch1, example foo_v1 and foo_v2 are the directories in branch1 where developer will update the latest one here foo_v2 and branch2 foo is same as the latest one of branch1 for an instance.

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.

Request for any help! let me know for any questions.
thanks!
-- 
Jagan.
Jagan Teki· Mar 14, 2014, 18:11 UTC · re: Jagan Teki · lore

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

Don't know what happen, I'm unable to join #git channel [23:40] <Jagan> hi [23:40] == Cannot send to channel: #git

Can any one help!
On Fri, Mar 14, 2014 at 11:09 PM, Jagan Teki <jagannadh.teki@gmail.com> wrote:
Show 29 quoted lines
> Hi,
>
> I have two branch in one repo that I need to maintain for 2 different
> deliveries.
> Say branch1 and branch2 in test.git repo.
>
> test.git
> - branch1
>      foo_v1/text.txt
>      foo_v2/text.txt
> - branch2
>      foo/text.txt
>
> branch1 is developers branch all source looks version'ed manner and
> branch2 is superset for branch1, example foo_v1 and foo_v2 are the directories
> in branch1 where developer will update the latest one here foo_v2 and branch2
> foo is same as the latest one of branch1 for an instance.
>
> 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.
>
> Request for any help! let me know for any questions.
>
>
> thanks!
> --
> Jagan.
-- 
Jagan.
Brandon McCaig· Mar 18, 2014, 17:11 UTC · re: Jagan Teki · lore

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

Jagan:
On Fri, Mar 14, 2014 at 1:11 PM, Jagan Teki <jagannadh.teki@gmail.com> wrote:
> Don't know what happen, I'm unable to join #git channel
> [23:40] <Jagan> hi
> [23:40] == Cannot send to channel: #git

I'm not sure if this is the problem that you were having, but #git on freenode is NickServ protected. You need to register with NickServ (a bot on the network) and identify yourself with it in order to be allowed to speak in #git. This cuts down on spam. You can `/msg NickServ help' to learn how to use it (and also Google will be your friend).

Alternatively, check the channel topic for an alternative solution.
Regards,
-- 
Brandon McCaig <bamccaig@gmail.com> <bamccaig@castopulence.org>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'
Andrew Wong· Mar 14, 2014, 19:18 UTC · re: Jagan Teki · lore

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

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).

Jagan Teki· Mar 14, 2014, 20:01 UTC · re: Andrew Wong · lore

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

On Sat, Mar 15, 2014 at 12:48 AM, Andrew Wong <andrew.kw.w@gmail.com> wrote:
Show 13 quoted lines
> 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.

thanks!
-- 
Jagan.
Andrew Wong· Mar 14, 2014, 20:37 UTC · re: Jagan Teki · lore

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

On Fri, Mar 14, 2014 at 4:01 PM, Jagan Teki <jagannadh.teki@gmail.com> wrote:
Show 19 quoted lines
> 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'
Jagan Teki· Mar 14, 2014, 20:57 UTC · re: Andrew Wong · lore

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

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.
Andrew Wong· Mar 14, 2014, 21:57 UTC · re: Jagan Teki · lore

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

On Fri, Mar 14, 2014 at 4:57 PM, Jagan Teki <jagannadh.teki@gmail.com> wrote:
Show 17 quoted lines
> 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")

Does the foo_v2/test.txt file already exist in branch2 before you try to apply? i.e. does foo/test.txt exist in branch2?

What might be happening is: the commit modifies foo_v2/test.txt on branch1, but foo/test.txt doesn't exist on branch2. So even when you use the subtree option, there's no foo/test.txt on branch2 to "receive" the changes of foo_v2/test.txt. This is an actual conflict that git doesn't know what to do, so you have resolve it. This probably means one of two things for you:

1. You _want_ foo/test.txt on branch2, then:
        git add foo/foo_v2/test.txt    # get the entire test.txt file
from that commit on branch1
        git mv foo/foo_v2/test.txt foo/test.txt    # move/rename the
file to the right location
2. You _don't_ want foo/test.txt on branch2, then:
        git rm foo/foo_v2/test.txt    # just remove it
And then run "git cherry-pick --continue" to continue with the cherry-pick.
Brandon McCaig· Mar 18, 2014, 17:18 UTC · re: Jagan Teki · lore

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

Jagan:
On Fri, Mar 14, 2014 at 12:39 PM, Jagan Teki <jagannadh.teki@gmail.com> wrote:
> Hi,
Hello,
Show 22 quoted lines
> I have two branch in one repo that I need to maintain for 2 different
> deliveries.
> Say branch1 and branch2 in test.git repo.
>
> test.git
> - branch1
>      foo_v1/text.txt
>      foo_v2/text.txt
> - branch2
>      foo/text.txt
>
> branch1 is developers branch all source looks version'ed manner and
> branch2 is superset for branch1, example foo_v1 and foo_v2 are the directories
> in branch1 where developer will update the latest one here foo_v2 and branch2
> foo is same as the latest one of branch1 for an instance.
>
> 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.
>
> Request for any help! let me know for any questions.

This just sounds like a painful workflow to me. I would suggest not doing this at all, but rather using tags to mark specific releases, and using individual branches for continued development (e.g., stable or v1.x or whatever is most appropriate). You can have unstable or master or dev or whatever for developers to work on freely without breaking releases (albeit, there are many different workflows you can use to manage the transition from unstable to stable code).

I would avoid using subtrees (subdirectories) within a Git repository to represent different releases of the code. Git already tracks versions. That is redundant and messy. It's really an outdated way of thinking about version control.

/my 2 cents
Regards,
-- 
Brandon McCaig <bamccaig@gmail.com> <bamccaig@castopulence.org>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'

← back to recent threads