Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cherry-pick merge commits?

Tags:

git

I need to cherry pick a range of commits, where I found commits like this:

Merge "TICKET-100: Some commit message" into master

< some other commits >

TICKET-100: Some commit message

I checked the content and its the same for both commits. Can I only cherry pick the first, and ignore the one starting with "Merge"? How are they related?

like image 843
jhthewow Avatar asked Sep 08 '25 03:09

jhthewow


2 Answers

Lets assume you have something like this:

X - master
|
|
M
|\
| \
X  B - merged_feature_branch
|  |
|  |
X  A    X - cherry_pick_destination
| /     |
|/      |
X       X
|      /
|     /

Now you have two choices:

  • cherry pick only A and B
  • cherry pick M against first parent (-m 1)

Both solution will introduce same change, but IMHO first approach is more readable. In case if some conflicts where resolved when committing M then second option may be preferred..

like image 151
Marek R Avatar answered Sep 10 '25 12:09

Marek R


If you have to cherry-pick a range of commits without the merge commits, rather than doing

git cherry-pick A..B

You can put the range into a subcommand where you suppress merge commits :

git cherry-pick $(git rev-list --no-merges A..B)
like image 26
Romain Valeri Avatar answered Sep 10 '25 12:09

Romain Valeri