threads / discuss / 7756

cherry-pick --since ?

Subject: cherry-pick --since ?

## tl;dr

12 messages between Apr 20, 2007 and Jul 17, 2009.

replies: 11people: 7as markdown or json

Brandon Casey· Apr 20, 2007, 16:20 UTC · lore
Is there functionality to allow something akin to
a
    git cherry-pick --since <commit>

or maybe syntax similar to git cherry where the upstream, head, and limit can be specified. Or the .. syntax would work.

Here's my use case:
Two branches, 'A' and 'B'.
'A' is the master branch.
'B' was forked some time ago and is in bug fix only mode.
Much of 'A' and 'B' are still the same, but there have been
   some intrusive changes made to 'A' that should not go into 'B'.
   This is also why I can't just pull from 'B'. rebase may work,
   but then of course all of the commit id's change.

When changes are made in 'B' I currently cherry-pick each commit into 'A' (where possible). This can be tedious when there are many commits. I can use git cherry to show me which commits should be cherry-picked, it would be nice if I could cherry-pick a range of commits.

I am not subscribed to the list so please cc me. I hope this is ok, if not let me know and I will subscribe. I am only a casual read of the list.

-brandon
Alex Riesen· Apr 20, 2007, 18:55 UTC · re: Brandon Casey · lore

Re: cherry-pick --since ?

Brandon Casey, Fri, Apr 20, 2007 18:20:32 +0200:
> Is there functionality to allow something akin to a
>
>    git cherry-pick --since <commit>
> 
git format-patch --stdin --binary --full-index -k from..to | git am -k -3
David Kågedal· Apr 22, 2007, 12:06 UTC · re: Alex Riesen · lore

Re: cherry-pick --since ?

Alex Riesen <raa.lkml@gmail.com> writes:
Show 7 quoted lines
> Brandon Casey, Fri, Apr 20, 2007 18:20:32 +0200:
>> Is there functionality to allow something akin to a
>>
>>    git cherry-pick --since <commit>
>> 
>
> git format-patch --stdin --binary --full-index -k from..to | git am -k -3
I guess you meant --stdout rather than --stdin here.
-- 
David Kågedal
Junio C Hamano· Apr 20, 2007, 23:05 UTC · re: Brandon Casey · lore

Re: cherry-pick --since ?

Brandon Casey <casey@nrlssc.navy.mil> writes:
Show 15 quoted lines
> Is there functionality to allow something akin to
> a
>    git cherry-pick --since <commit>
>
> or maybe syntax similar to git cherry where the upstream, head,
> and limit can be specified. Or the .. syntax would work.
>
>
> Here's my use case:
>
> Two branches, 'A' and 'B'.
> 'A' is the master branch.
> 'B' was forked some time ago and is in bug fix only mode.
> Much of 'A' and 'B' are still the same, but there have been
>   some intrusive changes made to 'A' that should not go into 'B'.

You forgot to say "My objective is to make sure all the good fixes in B are forward ported to A" but I am assuming that is the case.

>   This is also why I can't just pull from 'B'. rebase may work,
>   but then of course all of the commit id's change.

I do not understand why you cannot merge 'B' into 'A'. From the commit ancestry perspective, merging is exactly the right thing to do if your goal is to forward port all fixes in B to A.

Brandon Casey· Apr 23, 2007, 17:52 UTC · re: Junio C Hamano · lore

Re: cherry-pick --since ?

On Fri, 20 Apr 2007, Junio C Hamano wrote:
Show 21 quoted lines
> Brandon Casey <casey@nrlssc.navy.mil> writes:
>
>> Is there functionality to allow something akin to
>> a
>>    git cherry-pick --since <commit>
>>
>> or maybe syntax similar to git cherry where the upstream, head,
>> and limit can be specified. Or the .. syntax would work.
>>
>>
>> Here's my use case:
>>
>> Two branches, 'A' and 'B'.
>> 'A' is the master branch.
>> 'B' was forked some time ago and is in bug fix only mode.
>> Much of 'A' and 'B' are still the same, but there have been
>>   some intrusive changes made to 'A' that should not go into 'B'.
>
> You forgot to say "My objective is to make sure all the good
> fixes in B are forward ported to A" but I am assuming that is
> the case.

Yes, that is the case, but the flow is both ways. Other developers may implement fixes in 'A', which must be backported to 'B'. They don't care about 'B'.

Show 6 quoted lines
>>   This is also why I can't just pull from 'B'. rebase may work,
>>   but then of course all of the commit id's change.
>
> I do not understand why you cannot merge 'B' into 'A'.  From the
> commit ancestry perspective, merging is exactly the right thing
> to do if your goal is to forward port all fixes in B to A.

I thought I recalled having problems with a different tree and a similar situation, where a merge did not do what I expected. I'll have to take a look at that one again and post a scenario if I find one.

I just tried a pull from 'B' into 'A' with this tree, and it worked. The need to cherry-pick from 'A' into 'B' still exists though. The work around using format-patch that Alex suggested does work. Being able to cherry-pick a range in a more direct way seems like it would be useful though.

-brandon
Junio C Hamano· Apr 23, 2007, 19:32 UTC · re: Brandon Casey · lore

Re: cherry-pick --since ?

Brandon Casey <casey@nrlssc.navy.mil> writes:
Show 18 quoted lines
> On Fri, 20 Apr 2007, Junio C Hamano wrote:
>> Brandon Casey <casey@nrlssc.navy.mil> writes:
>> ...
>>> Here's my use case:
>>>
>>> Two branches, 'A' and 'B'.
>>> 'A' is the master branch.
>>> 'B' was forked some time ago and is in bug fix only mode.
>>> Much of 'A' and 'B' are still the same, but there have been
>>>   some intrusive changes made to 'A' that should not go into 'B'.
>>
>> You forgot to say "My objective is to make sure all the good
>> fixes in B are forward ported to A" but I am assuming that is
>> the case.
> 
> Yes, that is the case, but the flow is both ways. Other developers
> may implement fixes in 'A', which must be backported to 'B'. They
> don't care about 'B'.

That shows a problem in the project management that needs to be fixed independent of what SCM tool you use, doesn't it?

I do not think you would necessarily want to have a VC tsar to say "No, that is perfectly valid fix for the maintenance branch and you should make it go through the maintenance branch, do not directly commit to the master". People should be able to self-police that, with a general, shared understanding of what the overall process is, and can strive to make it easier for everybody.

Even with that, mistakes can happen, and sometimes you may realize that a fix or enhancement is applicable to the maintenance branch as well long after it hit the master branch. I would not disagree that you would need to have a way to deal with the ones that need backporting by cherry-picking (otherwise we would not have git-cherry-pick). And I am certainly not against a cherry-pick that can do more than one commit. What I am saying is that having to cherry-pick should be the exception, not the norm, and otherwise there is something wrong in the process.

If you want to do a cherry-pick that handles more than one commit, I think you need to worry about sequencing -- how to let the user continue after aborting in the middle and having him resolve conflicts. What "git-rebase --continue" does already can be used as a model for you to mimick in such an implementation.

Brandon Casey· Apr 23, 2007, 23:18 UTC · re: Junio C Hamano · lore

Re: cherry-pick --since ?

On Mon, 23 Apr 2007, Junio C Hamano wrote:
Show 31 quoted lines
> Brandon Casey <casey@nrlssc.navy.mil> writes:
>
>> On Fri, 20 Apr 2007, Junio C Hamano wrote:
>>> Brandon Casey <casey@nrlssc.navy.mil> writes:
>>> ...
>>>> Here's my use case:
>>>>
>>>> Two branches, 'A' and 'B'.
>>>> 'A' is the master branch.
>>>> 'B' was forked some time ago and is in bug fix only mode.
>>>> Much of 'A' and 'B' are still the same, but there have been
>>>>   some intrusive changes made to 'A' that should not go into 'B'.
>>>
>>> You forgot to say "My objective is to make sure all the good
>>> fixes in B are forward ported to A" but I am assuming that is
>>> the case.
>>
>> Yes, that is the case, but the flow is both ways. Other developers
>> may implement fixes in 'A', which must be backported to 'B'. They
>> don't care about 'B'.
>
> That shows a problem in the project management that needs to be
> fixed independent of what SCM tool you use, doesn't it?
>
> I do not think you would necessarily want to have a VC tsar to
> say "No, that is perfectly valid fix for the maintenance branch
> and you should make it go through the maintenance branch, do not
> directly commit to the master".  People should be able to
> self-police that, with a general, shared understanding of what
> the overall process is, and can strive to make it easier for
> everybody.
Agreed.

I think our case is more similar to a linux 2.6.20 branch and a 2.6.21 branch. Everybody's working on 2.6.21, but maybe someone is still relying on 2.6.20. That person implements their patches on 2.6.20 and pushes them to 2.6.21. Meanwhile, important fixes may be applied to 2.6.21 which is the official development version. So those fixes that are applicable to 2.6.20 must be pulled from 2.6.21 by the developer with the interest in 2.6.20.

Comments below noted, and thanks for your help.
-brandon
Show 19 quoted lines
> Even with that, mistakes can happen, and sometimes you may
> realize that a fix or enhancement is applicable to the
> maintenance branch as well long after it hit the master branch.
> I would not disagree that you would need to have a way to deal
> with the ones that need backporting by cherry-picking (otherwise
> we would not have git-cherry-pick).  And I am certainly not
> against a cherry-pick that can do more than one commit.  What I
> am saying is that having to cherry-pick should be the exception,
> not the norm, and otherwise there is something wrong in the
> process.
>
> If you want to do a cherry-pick that handles more than one
> commit, I think you need to worry about sequencing -- how to let
> the user continue after aborting in the middle and having him
> resolve conflicts.  What "git-rebase --continue" does already
> can be used as a model for you to mimick in such an
> implementation.
>
>
bshOriginal· Jul 16, 2009, 08:11 UTC · re: Brandon Casey · lore

Git range merge (cherry-pick a range)

Playing around with GIT, we encountered the following strange situation for which we would like to have an answer:

Scenario ========

We want to merge the range B to D from branch B1 to master
Master:       o-
                  \
Branch B1:      A-B-C-D-E
Commit B:
---------
FluidSolver::FluidSolver(int argc, char* argv[]) {
    init(argc, argv);
    // test edit 1: a + b
}
Commit C:
--------
FluidSolver::FluidSolver(int argc, char* argv[]) {
    init(argc, argv);
    // test edit 1: a + b
    // test edit 2: a - b
}
Commit D:
--------
FluidSolver::FluidSolver(int argc, char* argv[]) {
    init(argc, argv);
    // test edit 1: a + b
    // test edit 2: a - b
    // test edit 3: a * b
}
Commit E:
--------
FluidSolver::FluidSolver(int argc, char* argv[]) {
    init(argc, argv);
    // test edit 1: a + b
    // test edit 2: a - b
    // test edit 3: a * b
    // test edit 4: a / b
}

Range merge (the GIT way): =========================

1) Switch to Branch B1
2) Create a temporary branch which does not contain anything beyond commit D
   $ git checkout -b volatileBranch D
    Master:                 o-
                                \
    Branch B1:                A-B-C-D-E
                                                \
    Branch volatileBranch:              (A)-(B)-(C)-(D)
3) Rebase volatile branch to master from commit (B) to master's HEAD
   git rebase --onto master (A) 
    Branch volatileBranch:   (B)-(C)-(D)
                                     /
    Master:                      o-
                                     \
    Branch B1:                   A-B-C-D-E
                                       

Rebasing output: ----------------

First, rewinding head to replay your work on top of it...
Applying: test edit 2: a - b
error: patch failed: fluidsolver.cpp:28
error: fluidsolver.cpp: patch does not apply
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging fluidsolver.cpp
CONFLICT (content): Merge conflict in fluidsolver.cpp
Failed to merge in the changes.
Patch failed at 0001 test edit 2: a - b

When you have resolved this problem run "git rebase --continue". If you would prefer to skip this patch, instead run "git rebase --skip". To restore the original branch and stop rebasing run "git rebase --abort".

Conflicts:
----------
FluidSolver::FluidSolver(int argc, char* argv[]) {
    init(argc, argv);
<<<<<<< HEAD:fluidsolver.cpp
=======
    // test edit 1: a + b
    // test edit 2: a - b
>>>>>>> test edit 2: a - b:fluidsolver.cpp
}

After manually resolving the conflict and continuing the rebasing with git rebase --continue, we are finally finished.

Since we only had updates in branch 1, it is astonishing that we get a conflict at all. Same situation works like a charme in subversion. We would be happy to get an explanation for this merge bahaviour, since many edits in large projects could as a matter of principle result a lot of merge conflicts which all have to be treated manually.

We believe that GIT's interface for range merges needs to get more user friendly. Since steps 1) - 3) use already developed components of GIT, there should be a layer above 'em which performs a range merge by internally calling 1) - 3).

Example: git cherry-pick $from_branch@startCommitHash
$to_branch@endCommitHash 
Greetings,
Babak Sayyid Hosseini
-- 
View this message in context: http://www.nabble.com/cherry-pick---since---tp10105685p24512201.html
Sent from the git mailing list archive at Nabble.com.
Michael J Gruber· Jul 16, 2009, 11:36 UTC · re: bshOriginal · lore

Re: Git range merge (cherry-pick a range)

bshOriginal venit, vidit, dixit 16.07.2009 10:11:
Show 14 quoted lines
> 
> Playing around with GIT, we encountered the following strange situation for
> which we would
> like to have an answer:
> 
> Scenario
> ========
> 
> We want to merge the range B to D from branch B1 to master
> 
> Master:       o-
>                   \
> Branch B1:      A-B-C-D-E
> 

Did you use a monospaced font when composing this e-mail? All graphs come out disconnect/distorted when reading your e-mail with a monospaced font.

I assume that above, a is the first additional commit of B1 which branches off o.

Show 100 quoted lines
> 
> Commit B:
> ---------
> FluidSolver::FluidSolver(int argc, char* argv[]) {
>     init(argc, argv);
>     // test edit 1: a + b
> }
> 
> Commit C:
> --------
> FluidSolver::FluidSolver(int argc, char* argv[]) {
>     init(argc, argv);
>     // test edit 1: a + b
>     // test edit 2: a - b
> }
> 
> Commit D:
> --------
> FluidSolver::FluidSolver(int argc, char* argv[]) {
>     init(argc, argv);
>     // test edit 1: a + b
>     // test edit 2: a - b
>     // test edit 3: a * b
> }
> 
> Commit E:
> --------
> FluidSolver::FluidSolver(int argc, char* argv[]) {
>     init(argc, argv);
>     // test edit 1: a + b
>     // test edit 2: a - b
>     // test edit 3: a * b
>     // test edit 4: a / b
> }
> 
> 
> Range merge (the GIT way):
> =========================
> 
> 1) Switch to Branch B1
> 
> 2) Create a temporary branch which does not contain anything beyond commit D
> 
>    $ git checkout -b volatileBranch D
> 
>     Master:                 o-
>                                 \
>     Branch B1:                A-B-C-D-E
>                                                 \
>     Branch volatileBranch:              (A)-(B)-(C)-(D)
> 
> 3) Rebase volatile branch to master from commit (B) to master's HEAD
>    git rebase --onto master (A) 
> 
> 
>     Branch volatileBranch:   (B)-(C)-(D)
>                                      /
>     Master:                      o-
>                                      \
>     Branch B1:                   A-B-C-D-E
>                                        
> 
> Rebasing output:
> ----------------
> 
> First, rewinding head to replay your work on top of it...
> Applying: test edit 2: a - b
> error: patch failed: fluidsolver.cpp:28
> error: fluidsolver.cpp: patch does not apply
> Using index info to reconstruct a base tree...
> Falling back to patching base and 3-way merge...
> Auto-merging fluidsolver.cpp
> CONFLICT (content): Merge conflict in fluidsolver.cpp
> Failed to merge in the changes.
> Patch failed at 0001 test edit 2: a - b
> 
> 
> When you have resolved this problem run "git rebase --continue".
> If you would prefer to skip this patch, instead run "git rebase --skip".
> To restore the original branch and stop rebasing run "git rebase --abort".
> 
> 
> Conflicts:
> ----------
> FluidSolver::FluidSolver(int argc, char* argv[]) {
>     init(argc, argv);
> <<<<<<< HEAD:fluidsolver.cpp
> =======
>     // test edit 1: a + b
>     // test edit 2: a - b
>>>>>>>> test edit 2: a - b:fluidsolver.cpp
> }
> 
> 
> After manually resolving the conflict and continuing the rebasing 
> with git rebase --continue, we are finally finished.
> 
> Since we only had updates in branch 1, it is astonishing that we get a
> conflict at all.
> Same situation works like a charme in subversion.

Ahem, how could /anything/ work like a charm in subversion? (I've been using it myself.)

Seriously, if, in subversion, you merge -rA:D onto master then subversion only computes the diff between A and D and applies it to master. You an do this in git as well, of course, but that's not a merge and does not preserve individual commit messages.

Show 14 quoted lines
> We would be happy to get an explanation for this merge bahaviour, since 
> many edits in large projects could as a matter of principle result a lot of
> merge conflicts
> which all have to be treated manually.
> 
> We believe that GIT's interface for range merges needs to get more user
> friendly.
> Since steps 1) - 3) use already developed components of GIT, there should be
> a layer above 'em
> which performs a range merge by internally calling 1) - 3).
> 
> Example: git cherry-pick $from_branch@startCommitHash
> $to_branch@endCommitHash 
> 

If I read you graphs correctly you could just as well fast-forward master to D (using reset or merge) and then "rebase -i" in order to remove A.

Alternatively, you can use "git format-patch --stdout revrange | git am".
Michael
Daniel Barkalow· Jul 16, 2009, 16:27 UTC · re: bshOriginal · lore

Re: Git range merge (cherry-pick a range)

On Thu, 16 Jul 2009, bshOriginal wrote:
Show 89 quoted lines
> 
> Playing around with GIT, we encountered the following strange situation for
> which we would
> like to have an answer:
> 
> Scenario
> ========
> 
> We want to merge the range B to D from branch B1 to master
> 
> Master:       o-
>                   \
> Branch B1:      A-B-C-D-E
> 
> 
> Commit B:
> ---------
> FluidSolver::FluidSolver(int argc, char* argv[]) {
>     init(argc, argv);
>     // test edit 1: a + b
> }
> 
> Commit C:
> --------
> FluidSolver::FluidSolver(int argc, char* argv[]) {
>     init(argc, argv);
>     // test edit 1: a + b
>     // test edit 2: a - b
> }
> 
> Commit D:
> --------
> FluidSolver::FluidSolver(int argc, char* argv[]) {
>     init(argc, argv);
>     // test edit 1: a + b
>     // test edit 2: a - b
>     // test edit 3: a * b
> }
> 
> Commit E:
> --------
> FluidSolver::FluidSolver(int argc, char* argv[]) {
>     init(argc, argv);
>     // test edit 1: a + b
>     // test edit 2: a - b
>     // test edit 3: a * b
>     // test edit 4: a / b
> }
> 
> 
> Range merge (the GIT way):
> =========================
> 
> 1) Switch to Branch B1
> 
> 2) Create a temporary branch which does not contain anything beyond commit D
> 
>    $ git checkout -b volatileBranch D
> 
>     Master:                 o-
>                                 \
>     Branch B1:                A-B-C-D-E
>                                                 \
>     Branch volatileBranch:              (A)-(B)-(C)-(D)
> 
> 3) Rebase volatile branch to master from commit (B) to master's HEAD
>    git rebase --onto master (A) 
> 
> 
>     Branch volatileBranch:   (B)-(C)-(D)
>                                      /
>     Master:                      o-
>                                      \
>     Branch B1:                   A-B-C-D-E
>                                        
> 
> Rebasing output:
> ----------------
> 
> First, rewinding head to replay your work on top of it...
> Applying: test edit 2: a - b
> error: patch failed: fluidsolver.cpp:28
> error: fluidsolver.cpp: patch does not apply
> Using index info to reconstruct a base tree...
> Falling back to patching base and 3-way merge...
> Auto-merging fluidsolver.cpp
> CONFLICT (content): Merge conflict in fluidsolver.cpp
> Failed to merge in the changes.
> Patch failed at 0001 test edit 2: a - b

What's happening here is that the first commit you're keeping adds an edit to a version of the file which has the first edit as well, and that first edit is right next to the second edit, and so it's reasonably likely that the second edit has to be done differently in order to not require the first edit.

Show 15 quoted lines
> When you have resolved this problem run "git rebase --continue".
> If you would prefer to skip this patch, instead run "git rebase --skip".
> To restore the original branch and stop rebasing run "git rebase --abort".
> 
> 
> Conflicts:
> ----------
> FluidSolver::FluidSolver(int argc, char* argv[]) {
>     init(argc, argv);
> <<<<<<< HEAD:fluidsolver.cpp
> =======
>     // test edit 1: a + b
>     // test edit 2: a - b
> >>>>>>> test edit 2: a - b:fluidsolver.cpp
> }

This is the merge conflict output for the case where you're applying a change which is based on a version with some of the final code already there to a base that doesn't have that code. It's not a necessary conflict, but it is a likely conflict (that is, there's a unique logical guess as to the right resolution, but there's also a good change that the resulting code doesn't work). Of course, if the edits actually overlap, it becomes a necessary conflict.

Show 6 quoted lines
> After manually resolving the conflict and continuing the rebasing 
> with git rebase --continue, we are finally finished.
> 
> Since we only had updates in branch 1, it is astonishing that we get a
> conflict at all.
> Same situation works like a charme in subversion.
Except when it generates broken code like a charm...
Show 13 quoted lines
> We would be happy to get an explanation for this merge bahaviour, since 
> many edits in large projects could as a matter of principle result a lot of
> merge conflicts
> which all have to be treated manually.
> 
> We believe that GIT's interface for range merges needs to get more user
> friendly.
> Since steps 1) - 3) use already developed components of GIT, there should be
> a layer above 'em
> which performs a range merge by internally calling 1) - 3).
> 
> Example: git cherry-pick $from_branch@startCommitHash
> $to_branch@endCommitHash 
The main issue is the:
 git ??? --continue

that you use after you resolve any conflicts. The existing components need to be reorganized in order to support doing the correct later steps when a multi-step operation supplied by a higher layer was previously suspended for user assistance in the middle.

	-Daniel
*This .sig left intentionally blank*
bshOriginal· Jul 17, 2009, 08:41 UTC · re: bshOriginal · lore

Re: Git range merge (cherry-pick a range)

On Thu, Jul 16, 2009 at 2:44 PM, Michael J Gruber <git@drmicha.warpmail.net> wrote:

    Babak S. H. venit, vidit, dixit 16.07.2009 14:16:
    >>> Hello Micheal,
    >>> thank you for the response... I will try to answer inline as I
read...
    
    >>>>     Did you use a monospaced font when composing this e-mail? All
graphs
    >>>>     come out disconnect/distorted when reading your e-mail with a
monospaced
    >>>>     font.
    
    
    >>> What a pity. I pasted the text out of the editor (vi | Font: lucida
    >>> console 8) in the web form.
    >>> Anyway I attach my original posting in a file to this email. I hope
you
    >>> can open that undistorted.
    
    >>Yep, it's fine.
    
    >>>>    I assume that above, a is the first additional commit of B1
which
    >>>>    branches off o.
    >>> Correct.
    
   
    >>>>> Commit B:
    >>>>> ---------
    >>>>> FluidSolver::FluidSolver(int argc, char* argv[]) {
    >>>>>     init(argc, argv);
    >>>>>     // test edit 1: a + b
    >>>>> }
    >>>>>
    >>>>> Commit C:
    >>>>> --------
    >>>>> FluidSolver::FluidSolver(int argc, char* argv[]) {
    >>>>>     init(argc, argv);
    >>>>>     // test edit 1: a + b
    >>>>>     // test edit 2: a - b
    >>>>> }
    >>>>>
    >>>>> Commit D:
    >>>>> --------
    >>>>> FluidSolver::FluidSolver(int argc, char* argv[]) {
    >>>>>     init(argc, argv);
    >>>>>     // test edit 1: a + b
    >>>>>     // test edit 2: a - b
    >>>>>     // test edit 3: a * b
    >>>>> }
    >>>>>
    >>>>> Commit E:
    >>>>> --------
    >>>>> FluidSolver::FluidSolver(int argc, char* argv[]) {
    >>>>>     init(argc, argv);
    >>>>>     // test edit 1: a + b
    >>>>>     // test edit 2: a - b
    >>>>>     // test edit 3: a * b
    >>>>>     // test edit 4: a / b
    >>>>> }
    >>>>>
    >>>>>
    >>>>> Range merge (the GIT way):
    >>>>> =========================
    >>>>>
    >>>>> 1) Switch to Branch B1
    >>>>>
    >>>>> 2) Create a temporary branch which does not contain anything
    >>>>>     beyond commit D
    >>>>>
    >>>>>    $ git checkout -b volatileBranch D
    >>>>>
    >>>>>     Master:                o-
    >>>>>                                 \
    >>>>>     Branch B1:              A-B-C-D-E
    >>>>>                                               \
    >>>>>     Branch volatileBranch:              (A)-(B)-(C)-(D)
    >>>>>
    >>>>> 3) Rebase volatile branch to master from commit (B) to master's
HEAD
    >>>>>    git rebase --onto master (A)
    >>>>>
    >>>>>
    >>>>>     Branch volatileBranch:   (B)-(C)-(D)
    >>>>>                                      /
    >>>>>     Master:                      o-
    >>>>>                                      \
    >>>>>     Branch B1:                    A-B-C-D-E
    >>>>>
    >>>>>
    >>>>> Rebasing output:
    >>>>> ----------------
    >>>>>
    >>>>> First, rewinding head to replay your work on top of it...
    >>>>> Applying: test edit 2: a - b
    >>>>> error: patch failed: fluidsolver.cpp:28
    >>>>> error: fluidsolver.cpp: patch does not apply
    >>>>> Using index info to reconstruct a base tree...
    >>>>> Falling back to patching base and 3-way merge...
    >>>>> Auto-merging fluidsolver.cpp
    >>>>> CONFLICT (content): Merge conflict in fluidsolver.cpp
    >>>>> Failed to merge in the changes.
    >>>>> Patch failed at 0001 test edit 2: a - b
    >>>>>
    >>>>>
    >>>>> When you have resolved this problem run "git rebase --continue".
    >>>>> If you would prefer to skip this patch, instead run "git rebase
--skip".
    >>>>> To restore the original branch and stop rebasing run "git rebase
--abort".
    >>>>> Conflicts:
    >>>>> ----------
    >>>>> FluidSolver::FluidSolver(int argc, char* argv[]) {
    >>>>>     init(argc, argv);
    >>>>> <<<<<<< HEAD:fluidsolver.cpp
    >>>>> =======
    >>>>>     // test edit 1: a + b
    >>>>>     // test edit 2: a - b
    >>>>>     >>>>>>>> test edit 2: a - b:fluidsolver.cpp
    >>>>> }
    
    >>>>> After manually resolving the conflict and continuing the rebasing
    >>>>> with git rebase --continue, we are finally finished.
    
    >>>>> Since we only had updates in branch 1, it is astonishing that we
get a
    >>>>> conflict at all.
    >>>>> Same situation works like a charme in subversion.
    
    >>>>     Ahem, how could /anything/ work like a charm in subversion?
(I've been
    >>>>     using it myself.)
   
    >>> Please let's try not to start a belief war. Every version control
    >>> systems has its quirks and we just
    >>> try to figure out what the problem in the above described scenario
is.
    >>Agreed. (Which is why I started the next paragraph with "Seriously,".)
   
    >>>>     Seriously, if, in subversion, you merge -rA:D onto master then
    >>>>     subversion only computes the diff between A and D and applies
it to
    >>>>     master. You an do this in git as well, of course, but that's
not a merge
    >>>>     and does not preserve individual commit messages.
    >>>>
    
    >>> Subversion does preserve individual commit messages.
    >>> Try to pass the --use-merge-history parameter to svn log.
    
    >> I have to admit that I've ever used svn 1.4x. I do belief though that
    >> even 1.5 makes a single commit in that situation and reconstructs the
    >> merge history from the metadata.
> Maybe. But it works and you can additionally inspect diffs between
> revisions.
 
  
    >>>>> We would be happy to get an explanation for this merge bahaviour,
    >>>>> since
    >>>>> many edits in large projects could as a matter of principle result
    >>>>> a lot of merge conflicts which all have to be treated manually.
    >>>>> We believe that GIT's interface for range merges needs to get more
    >>>>> user friendly.
    >>>>> Since steps 1) - 3) use already developed components of GIT, there
    >>>>> should be a layer above 'em
    >>>>> which performs a range merge by internally calling 1) - 3).
    >>>>>
    >>>>> Example: git cherry-pick $from_branch@startCommitHash
    >>>>> $to_branch@endCommitHash
    >>     If I read you graphs correctly you could just as well
fast-forward
    >>     master to D (using reset or merge) and then "rebase -i" in order
to
    >>     remove A.
    >>
    >>     Alternatively, you can use "git format-patch --stdout revrange |
git
    >>     am".
   
    
    > Yes applying a patch is an alternative.
    > But don't you think git needs to provide a more user friendly
interface
    > for range merges?
    >> Sometimes it's only a matter of workflow. Have you tried the
suggestion
    >> above?

Yes, many ways lead to Rome.. Personally, I think most companies and open source coders are currently bound to subversion and are keen to start off with a more sophisticated version control system as e.g. git, mercurial or darcs. As they are already pretty familiar with subversion, I think it is clever to follow established and accepted workflows in case those workflows are really equivalent. This enhances the acceptability and is a pro for git in a direct comparison to the mentioned alternative distributed version control systems.

I tried out the patch alternative and apart from the fact that one of the patches could not be directly applied and as a result we again faced the same merge conflict, everything worked out the way it ought to.

 
    >> In general, in git it's preferable to have merges of feature branches
    >> rather than cherry picks. So you would rebase the feature branch
first
    >> (rebase -i to remove A) and then merge the result to master. Have you
    >> tried whether you get conflicts that way? It's really one rebase -i
and
    >> one merge.

No I must admit that I did not try that one out, but I believe it is pretty much the same thing I did. I branched from revision D dropping out revision E. Then I rebased in a way that everything above revision A was merge relevant cropping A. ==> A CROP B - C - D CROP E

 
    > If you want to use a patch approach then "git format-patch|git am" and
    > "git cherry" are your options. Currently, git cherry-pick accepts only
a
    > single commit, but if you want to pick the range B through D that
would
    > be B^..D in git lingo, so
    > git rev-list --reverse --topo-order B^..D | while read rev
    > do
    >   git cherry-pick $rev || break
    > done

The above lines look correct to me. But again, if git really wants to be the next king version control system, it has to be more user friendly. You and me are comfortable with the command line. There are a lot of GUI users though, that are overstrained with all that. I hope git implements a few more top level functions to simplify specific operations as it seems to be a really nice VCS.

Have a nicce day.
Babak Sayyid Hosseini
 
    > should do the job (untested!).
    > Cheers,
    > Michael
-- 
Regards.

Babak Sayyid Hosseini
-- 
View this message in context: http://www.nabble.com/cherry-pick---since---tp10105685p24530703.html
Sent from the git mailing list archive at Nabble.com.
Michael J Gruber· Jul 16, 2009, 12:44 UTC · lore

Re: Git range merge (cherry-pick a range)

Babak S. H. venit, vidit, dixit 16.07.2009 14:16:
> Hello Micheal,
> thank you for the response... I will try to answer inline as I read...
...
Show 11 quoted lines
> 
>     Did you use a monospaced font when composing this e-mail? All graphs
>     come out disconnect/distorted when reading your e-mail with a monospaced
>     font.
> 
> 
> 
> What a pity. I pasted the text out of the editor (vi | Font: lucida
> console 8) in the web form.
> Anyway I attach my original posting in a file to this email. I hope you
> can open that undistorted.
Yep, it's fine.
Show 128 quoted lines
> 
>  
> 
> 
> 
>     I assume that above, a is the first additional commit of B1 which
>     branches off o.
> 
> 
> 
> Correct.
> 
>  
> 
> 
> 
>     >
>     > Commit B:
>     > ---------
>     > FluidSolver::FluidSolver(int argc, char* argv[]) {
>     >     init(argc, argv);
>     >     // test edit 1: a + b
>     > }
>     >
>     > Commit C:
>     > --------
>     > FluidSolver::FluidSolver(int argc, char* argv[]) {
>     >     init(argc, argv);
>     >     // test edit 1: a + b
>     >     // test edit 2: a - b
>     > }
>     >
>     > Commit D:
>     > --------
>     > FluidSolver::FluidSolver(int argc, char* argv[]) {
>     >     init(argc, argv);
>     >     // test edit 1: a + b
>     >     // test edit 2: a - b
>     >     // test edit 3: a * b
>     > }
>     >
>     > Commit E:
>     > --------
>     > FluidSolver::FluidSolver(int argc, char* argv[]) {
>     >     init(argc, argv);
>     >     // test edit 1: a + b
>     >     // test edit 2: a - b
>     >     // test edit 3: a * b
>     >     // test edit 4: a / b
>     > }
>     >
>     >
>     > Range merge (the GIT way):
>     > =========================
>     >
>     > 1) Switch to Branch B1
>     >
>     > 2) Create a temporary branch which does not contain anything
>     beyond commit D
>     >
>     >    $ git checkout -b volatileBranch D
>     >
>     >     Master:                 o-
>     >                                   \
>     >     Branch B1:              A-B-C-D-E
>     >                                                  \
>     >     Branch volatileBranch:              (A)-(B)-(C)-(D)
>     >
>     > 3) Rebase volatile branch to master from commit (B) to master's HEAD
>     >    git rebase --onto master (A)
>     >
>     >
>     >     Branch volatileBranch:   (B)-(C)-(D)
>     >                                        /
>     >     Master:                      o-
>     >                                        \
>     >     Branch B1:                    A-B-C-D-E
>     >
>     >
>     > Rebasing output:
>     > ----------------
>     >
>     > First, rewinding head to replay your work on top of it...
>     > Applying: test edit 2: a - b
>     > error: patch failed: fluidsolver.cpp:28
>     > error: fluidsolver.cpp: patch does not apply
>     > Using index info to reconstruct a base tree...
>     > Falling back to patching base and 3-way merge...
>     > Auto-merging fluidsolver.cpp
>     > CONFLICT (content): Merge conflict in fluidsolver.cpp
>     > Failed to merge in the changes.
>     > Patch failed at 0001 test edit 2: a - b
>     >
>     >
>     > When you have resolved this problem run "git rebase --continue".
>     > If you would prefer to skip this patch, instead run "git rebase
>     --skip".
>     > To restore the original branch and stop rebasing run "git rebase
>     --abort".
>     >
>     >
>     > Conflicts:
>     > ----------
>     > FluidSolver::FluidSolver(int argc, char* argv[]) {
>     >     init(argc, argv);
>     > <<<<<<< HEAD:fluidsolver.cpp
>     > =======
>     >     // test edit 1: a + b
>     >     // test edit 2: a - b
>     >>>>>>>> test edit 2: a - b:fluidsolver.cpp
>     > }
>     >
>     >
>     > After manually resolving the conflict and continuing the rebasing
>     > with git rebase --continue, we are finally finished.
>     >
>     > Since we only had updates in branch 1, it is astonishing that we get a
>     > conflict at all.
>     > Same situation works like a charme in subversion.
> 
>     Ahem, how could /anything/ work like a charm in subversion? (I've been
>     using it myself.)
> 
> 
> 
> Please let's try not to start a belief war. Every version control
> systems has its quirks and we just
> try to figure out what the problem in the above described scenario is.
Agreed. (Which is why I started the next paragraph with "Seriously,".)
Show 15 quoted lines
> 
> 
>  
> 
> 
> 
>     Seriously, if, in subversion, you merge -rA:D onto master then
>     subversion only computes the diff between A and D and applies it to
>     master. You an do this in git as well, of course, but that's not a merge
>     and does not preserve individual commit messages.
> 
> 
> 
> Subversion does preserve individual commit messages.
> Try to pass the --use-merge-history parameter to svn log.

I have to admit that I've ever used svn 1.4x. I do belief though that even 1.5 makes a single commit in that situation and reconstructs the merge history from the metadata.

Show 35 quoted lines
> 
>  
> 
> 
> 
>     > We would be happy to get an explanation for this merge bahaviour,
>     since
>     > many edits in large projects could as a matter of principle result
>     a lot of
>     > merge conflicts
>     > which all have to be treated manually.
>     >
>     > We believe that GIT's interface for range merges needs to get more
>     user
>     > friendly.
>     > Since steps 1) - 3) use already developed components of GIT, there
>     should be
>     > a layer above 'em
>     > which performs a range merge by internally calling 1) - 3).
>     >
>     > Example: git cherry-pick $from_branch@startCommitHash
>     > $to_branch@endCommitHash
>     >
> 
>     If I read you graphs correctly you could just as well fast-forward
>     master to D (using reset or merge) and then "rebase -i" in order to
>     remove A.
> 
>     Alternatively, you can use "git format-patch --stdout revrange | git
>     am".
> 
> 
> Yes applying a patch is an alternative.
> But don't you think git needs to provide a more user friendly interface
> for range merges?

Sometimes it's only a matter of workflow. Have you tried the suggestion above?

In general, in git it's preferable to have merges of feature branches rather than cherry picks. So you would rebase the feature branch first (rebase -i to remove A) and then merge the result to master. Have you tried whether you get conflicts that way? It's really one rebase -i and one merge.

If you want to use a patch approach then "git format-patch|git am" and "git cherry" are your options. Currently, git cherry-pick accepts only a single commit, but if you want to pick the range B through D that would be B^..D in git lingo, so

git rev-list --reverse --topo-order B^..D | while read rev
do
  git cherry-pick $rev || break
done
should do the job (untested!).

Cheers, Michael

← back to recent threads