NullVoxPopuli NullVoxPopuli - 21 days ago 6
Git Question

How do I merge a specific commit from one branch into another in Git?

I have

BranchA
which is 113 commits ahead of
BranchB
.

But I only want the last 10 or so commits from
BranchA
merged into
BranchB
.

Is there a way to do this?

Answer

The git cherry-pick <commit> command allows you to take a single commit (from whatever branch) and, essentially, rebase it in your working branch.

Chapter 5 of the Pro Git book explains it better than I can, complete with diagrams and such; look for the section entitled "Rebasing and Cherry Picking Workflows". (The chapter on Rebasing is also good reading.)

Lastly, there are some good comments on the cherry-picking vs merging vs rebasing in another SO question.