Cherry-pick

Cherry-pick, essentially, will duplicate the changes from the original commit to a new commit of the current branch.

It is useful but not limited to such scenarios

  • When sometimes we want some but not all the commits from a branch, for example, porting back a bug fix from v2.0 to v1.8.

  • When we were too lazy or forgot to create a new branch for the commits, and after finished the work we realized the commits were done on the wrong branch. We'd like to create a new branch basing on the right commit/branch and cherry-pick these commits.

  • Sometimes it's much faster than a rebase. For example when master branch is way ahead from our current branch, rebasing will need to evaluate all the commits in between which is slow.

To cherry-pick in GitExtensions, first we select a couple of commits to cherry-pick (the order doesn't matter, GitExtensions always does the oldest one first), then right click to popup the context menu and select Cherry-Pick menu item. BTW, you can hold the CTRL key to select multiple commits.

Unticking the Automatically create a commit will only pick up the changes but not create the commit.

Ticking the Add commit reference to commit message will put the original commit SHA as part of the new commit message body. It's no point to

Command line

git cherry-pick <Commit SHA> [Another Commit SHA]
# use the -x switch to add commit reference to original commit
git cherry-pick -x <Commit SHA> [Another Commit SHA]

Last updated