Home > OS >  How to cherry-pick merge commits?
How to cherry-pick merge commits?

Time:03-30

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?

CodePudding user response:

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

CodePudding user response:

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)

CodePudding user response:

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.

  •  Tags:  
  • git
  • Related