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
| Flag | Meaning |
|---|---|
| -x | note the original hash in the new message |
| -n | apply and stage without committing |
| -e | edit the message |
| -m <parent> | pick a merge commit, choosing a side |
| <a>..<b> | a range; a itself is not included |
| --continue | go on after a conflict |
| --abort | undo the whole pick |
Examples
git cherry-pick a1b2c3dcopies that commit onto the current branch with a new hash
git cherry-pick -x a1b2c3dsame, with the source hash recorded in the message
git cherry-pick a1b2c3d^..d4e5f6acopies 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