Cherrypick - biswajitsundara/gitdoc GitHub Wiki

Cherry picking is the act of picking a commit from a branch and applying it to another.

  • git cherry-pick is a Git command that allows you to apply a specific commit from one branch to another branch.
  • It lets you pick a specific commit from one branch and apply it to another branch
  • without having to merge the entire branch.
  • This can be useful if you need to apply a specific fix or feature from one branch to another
  • without merging all the changes from that branch.

Syntax

git cherry-pick <commit-hash>

Workflow

  • Let's say you have two branches in your Git repository master and feature branch
  • You've made some changes to the feature-branch branch and committed them.
  • Now, you want to apply just one of those changes to the master branch.
  1. Switch to the master branch
git checkout master
  1. Find the commit hash of the specific change you want to apply.
  • You can use the git log command to view a list of all the commits in the feature branch
  • This will show you a list of all the commits in the feature branch, along with their commit hashes.
git log feature
  1. Copy the commit hash of the specific change you want to apply

  2. Use the git cherry-pick command to apply the change to the master branch

  • This will apply the changes from the specified commit to the master branch.
  • If there are any conflicts between the changes in the commit you're cherry-picking and the current state of the master branch,
  • Git will prompt you to resolve them before the cherry-pick can be completed.
git cherry-pick <commit-hash>