jhthewow
jhthewow

Reputation: 183

How to cherry-pick merge commits?

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?

Upvotes: 4

Views: 24928

Answers (3)

Marek R
Marek R

Reputation: 37512

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

Upvotes: 12

Maksym
Maksym

Reputation: 1

Maybe you can rebase your commits before merging? Try something like this:

git rebase -i HEAD~[commits count]

Now you must see a list with chosen commits. Before the first commit, to which you want to squash all other commits, must be a command pick.

squash - if you want to change the commit message and fixup - if not.

After rebasing you probably can merge only chosen changing.

Upvotes: 0

Romain Valeri
Romain Valeri

Reputation: 21908

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)

Upvotes: 8

Related Questions