Home·Terminal commands

git cherry-pick

git

Usage

git cherry-pick [-x] <commit>...

Copies a single commit onto the current branch as a new commit with a new hash, so merging that branch later can show the same change twice.

Common flags

FlagMeaning
-xnote the original hash in the new message
-napply and stage without committing
-eedit the message
-m <parent>pick a merge commit, choosing a side
<a>..<b>a range; a itself is not included
--continuego on after a conflict
--abortundo the whole pick

Examples

git cherry-pick a1b2c3d

copies that commit onto the current branch with a new hash

git cherry-pick -x a1b2c3d

same, with the source hash recorded in the message

git cherry-pick a1b2c3d^..d4e5f6a

copies a range, this time including a1b2c3d

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git cherry-pick do?

Copies a single commit onto the current branch as a new commit with a new hash, so merging that branch later can show the same change twice.

Q. How do I type it?

git cherry-pick [-x] <commit>... — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-cherry-pick