This command basically allows us to copy a single commit from one branch to another.

It’s very useful when we need to add a specific change from a commit without merging the entire branch, for example.

Contrast this with the way commit integration normally works in Git: when performing a Merge or Rebase, all commits from one branch are integrated.

Cherry-pick, on the other hand, allows us to select individual commits for integration. In this example, only C2 is integrated into the master branch, but not C4.

How to use the git cherry-pick command?

In its most basic form, we only need to provide the SHA identifier of the commit we want to integrate into our current HEAD branch:

$ git cherry-pick af01e0c

This way, the specified revision will directly be committed to our currently checked-out branch. If we would like to make some further modifications, we can also instruct Git to only add the commit’s changes to our Working Copy – without directly committing them:

$ git cherry-pick af01e0c --no-commit

By Shabazz

Software Engineer, MCSD, Web developer & Angular specialist

Leave a Reply

Your email address will not be published. Required fields are marked *