1.

What is "git cherry-pick"?

Answer»

Cherry picking in Git shifts a commit from one branch and apply it onto another one. This is indifferent to other ways like merge and re-bases which moves many COMMITS onto another branch. Make sure we are on the same branch we would like to apply the commit to.

  1. We will first move to master branch git CHECKOUT master
  2. Once we are on the same branch we run the following command:
    git cherry-pick <commit-hash>

Note :commit-hash: Unique identifier for  commit.

If we cherry-pick from a public repo branch, we should consider below command :

  • git cherry-pick -x <commit-hash>

This will ALWAYS generate a standardized commit message. This way, our team members can still keep track of the origin of the commit and may avoid merge conflicts in the future. If we have notes attached to the commit that does not follow the cherry-pick. To bring them over as well, we can use:

  • git notes copy <from> <to>

A common use case for cherry-picking is to forward- or back-port commits from a maintenance branch to a DEVELOPMENT branch.



Discussion

No Comment Found