Interview Q&A / Git & GitHub

AdvancedQuick answer1 min readUpdated 3 Oct 2026

How do you cherry-pick a merge commit?

SHORT ANSWER

Add -m 1 (or -m 2) to say which parent is the mainline, because a merge commit has two parents and Git cannot know which side's diff to copy.

Explain it simply

A merge commit is a junction with two incoming roads. 'Copy what this commit changed' is ambiguous: compared with which road?

With -m 1, Git diffs against the first parent, which is the branch you merged into. That produces the feature's net changes. Using -m 2 diffs against the branch that was merged in, which is rarely what you want. The same flag is needed for reverting merges. Most teams avoid this by cherry-picking the feature's individual commits or using squash merges.

Example

bash
git show --format=%P -s 9c1d2ef     # two parent hashes
git cherry-pick -m 1 9c1d2ef

What to say in the interview

"Merge commits have two parents, so cherry-pick needs -m to choose the mainline, usually -m 1. Without it Git errors out. I would usually avoid it and pick the individual commits instead."

#git#cherry-pick#merge

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.