Skip to content

Instantly share code, notes, and snippets.

@johngorithm
Last active March 21, 2019 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johngorithm/e6d9a5598510ef9be8de08a4c55dd87b to your computer and use it in GitHub Desktop.
Save johngorithm/e6d9a5598510ef9be8de08a4c55dd87b to your computer and use it in GitHub Desktop.

Description

Cherry picking in Git means to choose a commit from one branch and apply it onto another. This is in contrast with other ways such as merge and rebase which normally apply many commits onto another branch.

Usage

Make sure you are on the branch you want to apply the commit to.

git checkout master

Execute the following:

git cherry-pick <commit-hash>

N.B.: If you cherry-pick from a public branch, you should consider using

git cherry-pick -x <commit-hash>

This will generate a standardized commit message. This way, you (and your co-workers) can still keep track of the origin of the commit and may avoid merge conflicts in the future.

If you have notes attached to the commit they do not follow the cherry-pick. To bring them over as well, You have to use:

git notes copy <from> <to>

Learn more:

Git Cherry-pick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment