Drupal Developer
When you are working with a team of developers on a medium to large sized project, managing the changes between a number of git branches can become a complex task. Sometimes you don't want to merge a whole branch into another, and only need to pick one or two specific commits. This process is called 'cherry picking'.
I will try to explaining this through a scenario which will make it easier to understand.
Let’s say you are working in an project where you are making changes in a branch called new-features. You have already made a few commits but want to move just one of them into the master branch.
git checkout master
git cherry-pick d467740
This will cherry pick the commit with hash d467740 and add it as a new commit on the master branch. Note: it will have a new (and different) commit ID in the master branch.
If you want to cherry pick more than one commit in one go, you can add their commit IDs separated by a space:
git cherry-pick d467740 de906d4
git cherry-pick --continue
git cherry-pick --abort
After all this is done, you can simply push the new commits to the upstream repo (e.g origin) and get on with your day.
In case you needed to cherry pick a merge instead of a commit, you can use:
git cherry-pick -m 1 <hash>
Cherry picking is commonly discouraged in developer community. The main reason is because it creates a duplicate commit with the same changes and you lose the ability to track the history of the original commit. If you can merge, then you should use that instead of cherry picking. Use it with caution!
Here is some good material for broadening your knowledge: