30.1.11.5 Copying Changes Made By Revisions Between Branches

M-x vc-cherry-pick

Copy a single revision to branch checked out in this working tree.

Sometimes it is useful to copy a revision from one branch to another. This means creating a new revision with the same changes, log message and authorship information as an existing revision that can be found on another branch. This is often called cherry-picking the revision from one branch to another.

The most common case is copying a revision from a branch that won’t be merged (see Merging Branches) into your current branch. For example, your project might have a feature-frozen branch that accepts only bug fixes. Someone (possibly you) fixes a bug on the main development branch. You can then cherry-pick that revision onto the feature-frozen branch in order to fix the bug there, too. This is called backporting the revision, or backporting the fix.

You can use the command M-x vc-cherry-pick to cherry-pick revisions. It prompts for a revision to cherry-pick. It then pops up a buffer for you to edit the log message for the new revision. Normally the VC backend generates a log message including a reference to the revision you want to copy, so that the copy can be traced. If you wish, you can delete this reference before typing C-c C-c to conclude the cherry-pick.

Alternatively you can invoke the command with a prefix argument, i.e. C-u M-x vc-cherry-pick. In this case the log message from the source revision is used unmodified, and the cherry-pick happens immediately, without popping up a buffer for log message edits.

An alternative way to access this functionality is the log-view-cherry-pick command, bound to C in Log View mode buffers (see VC Change Log). Compared to using M-x vc-cherry-pick directly, this can make it easier to be sure you are cherry-picking the revision you intend.