Getting Git

A comprehensive video course from git init to Git Master.

Master: git cherry-pick


In this video we'll learn some of the additional options for git cherry-pick.

In init: git cherry-pick we saw how git cherry-pick can be used to copy a single commit into our branch.

We can also cherry pick a set of commits.

We can do this by passing multiple commits or a commit range.

Let's demonstrate this by referencing the commits from the working-quickly with some text comments.

First, let's run git log --oneline working-quickly.

If we wanted the first and last commit, we could run:

git cherry-pick SHA SHA

If we wanted the first and second commit, we could run:

git cherry-pick SHA SHA

Or instead, we could use a commit range:

git cherry-pick SHA^..SHA

Notice when using a commit range with git cherry-pick it does not include the from commit.

To include it, we can use the caret to reference the previous commit.

We can also pass the -n. Just as with git revert, -n applies the changes but does not make the commit.

This gives you a chance to edit the changes before making the commit.

Let's demonstrate this by running:

git cherry-pick -n SHA

If I run git status we'll see the changes were added and ready to be committed.

But if we run git log, we see it didn't make the commit.

You may not use git cherry-pick very often. Nonetheless, it's a precise command of Git Master.