How could cherry-pick other merge path?

452 Views Asked by At

I have this structure:

   B - C - D <- feature
  /         \  
 A-----------E <- master  
 ^ mytag

B, C and D commits are feature branch path. A is a common base. This feature is merged back into master as E commit. I have tagged (automatically) commit A.

I would like automatically without user intervention (from script), no matter how many commits are there in the feature branch to cherry pick "mytag" to "master" as A, E (in this case) in another branch.

Now if I do:

git checkout other    
git cherry-pick mytag..master

it will pick A, B, C, D and E commits. I would like it to pick commits only from master branch, i.e. A and E. Note: I don't want to merge into E in the opposide way. I want it feature into the master. And A to E is not sure that is branching at all. It could be A --- E. Just I need something like ".." operator, but to use other branch'es way.

Thanks for the help in advance!

In addition: The third branch were I should cherry-pick, should look like that after:

F - G - H - A - E <- other 

i.e. A and E will be cherry-picked in "other" branch.

1

There are 1 best solutions below

0
On

This is the answer:

call git cherry-pick -m 1 --first-parent mytag..master
if %errorlevel% == 128 then call git cherry-pick --first-parent mytag..master

--first-parent is undocumented option of cherry-pick. I saw it in log command and it is working for former, too. It is doing exactly what I need. To traverse first parent, not branch'es one as is by default.

git log --first-parent mytag..master

is returning only A and E commits. -m 1 option is used only for merge commits and fail for non-merge commits and vice verse. So I try with and if it fail - without.