WEBVTT
00:00:00.000 --> 00:00:01.200 align:middle line:90%
00:00:01.200 --> 00:00:03.580 align:middle line:84%
Another useful command
is git-cherry-pick,
00:00:03.580 --> 00:00:05.410 align:middle line:84%
and what it allows
us to do is to bring
00:00:05.410 --> 00:00:07.170 align:middle line:84%
in the changes
that are introduced
00:00:07.170 --> 00:00:09.030 align:middle line:90%
by a specific commit.
00:00:09.030 --> 00:00:11.350 align:middle line:84%
So for example, let's say you're
working on a branch for a while
00:00:11.350 --> 00:00:13.561 align:middle line:84%
and you decide that you'd
want to throw away the branch.
00:00:13.561 --> 00:00:14.860 align:middle line:84%
You don't want to
work with it anymore,
00:00:14.860 --> 00:00:17.800 align:middle line:84%
but there is one change, one
commit that you made somewhere
00:00:17.800 --> 00:00:19.830 align:middle line:84%
in between-- somewhere in
the middle of all the changes
00:00:19.830 --> 00:00:20.630 align:middle line:90%
that you made.
00:00:20.630 --> 00:00:22.840 align:middle line:84%
And you just want to
pull in that one change.
00:00:22.840 --> 00:00:25.610 align:middle line:84%
Well, you can do that really
easily with cherry-pick.
00:00:25.610 --> 00:00:27.830 align:middle line:84%
Let's look at a
quick, simple example.
00:00:27.830 --> 00:00:30.230 align:middle line:84%
I'm going to create a feature
branch again, so get checkout.
00:00:30.230 --> 00:00:32.960 align:middle line:90%
00:00:32.960 --> 00:00:36.850 align:middle line:84%
Feature 6 this time, and
I'll just make it simple.
00:00:36.850 --> 00:00:40.540 align:middle line:84%
I'll echo out another change
to, let's see, three.txt.
00:00:40.540 --> 00:00:51.910 align:middle line:90%
00:00:51.910 --> 00:00:54.660 align:middle line:84%
If I look at the get log now,
the commit that I just made
00:00:54.660 --> 00:00:56.274 align:middle line:90%
is 4560.
00:00:56.274 --> 00:00:57.340 align:middle line:90%
So we can kind of remember that.
00:00:57.340 --> 00:00:58.950 align:middle line:90%
4560.
00:00:58.950 --> 00:01:00.680 align:middle line:84%
I'm going to check out
the master branch now,
00:01:00.680 --> 00:01:05.180 align:middle line:84%
and then I can say
git-cherry-pick, and-- oop.
00:01:05.180 --> 00:01:05.990 align:middle line:90%
I already forgot it.
00:01:05.990 --> 00:01:06.790 align:middle line:90%
Let's scroll back.
00:01:06.790 --> 00:01:08.040 align:middle line:90%
4560.
00:01:08.040 --> 00:01:09.160 align:middle line:90%
4560.
00:01:09.160 --> 00:01:09.960 align:middle line:90%
There we go.
00:01:09.960 --> 00:01:11.810 align:middle line:84%
And I can just provide the
first couple of characters
00:01:11.810 --> 00:01:13.830 align:middle line:84%
of the SHA-1 hash
and press Enter,
00:01:13.830 --> 00:01:16.670 align:middle line:84%
and it goes ahead and
applies that commit
00:01:16.670 --> 00:01:17.940 align:middle line:90%
to our master branch.
00:01:17.940 --> 00:01:20.581 align:middle line:84%
And I can take a look
at it with get log.
00:01:20.581 --> 00:01:25.200 align:middle line:90%
00:01:25.200 --> 00:01:27.110 align:middle line:84%
And we can see that
commit is clearly
00:01:27.110 --> 00:01:29.980 align:middle line:84%
pulled into the master branch
as the top level commit here.
00:01:29.980 --> 00:01:31.880 align:middle line:84%
I've created two
windows that we can see
00:01:31.880 --> 00:01:33.410 align:middle line:90%
the two branches side-by-side.
00:01:33.410 --> 00:01:35.510 align:middle line:84%
On the right is our
feature 6 branch
00:01:35.510 --> 00:01:38.170 align:middle line:84%
that we just pulled in this
commit from, and on the left
00:01:38.170 --> 00:01:39.290 align:middle line:90%
is our master branch.
00:01:39.290 --> 00:01:42.220 align:middle line:84%
I want to point out, again,
that the IDs of the hash
00:01:42.220 --> 00:01:46.280 align:middle line:84%
of the commits have changed,
so this commit is CF2D,
00:01:46.280 --> 00:01:48.240 align:middle line:90%
and this one is 4560.
00:01:48.240 --> 00:01:51.180 align:middle line:84%
But it point this one here
will point to the same tree
00:01:51.180 --> 00:01:54.040 align:middle line:84%
as this one, so they both
point to the same tree.
00:01:54.040 --> 00:01:56.410 align:middle line:84%
And the reason that the
commit IDs are different
00:01:56.410 --> 00:01:59.780 align:middle line:84%
is because, remember, that
this gets turned into a patch
00:01:59.780 --> 00:02:03.310 align:middle line:84%
and then it gets applied on
top of our master branch.
00:02:03.310 --> 00:02:05.120 align:middle line:84%
And during the
application process,
00:02:05.120 --> 00:02:06.490 align:middle line:84%
get is going to go
ahead and create
00:02:06.490 --> 00:02:08.520 align:middle line:90%
a separate commit for it.
00:02:08.520 --> 00:02:10.310 align:middle line:84%
This was a bit of a
contrived example.
00:02:10.310 --> 00:02:12.540 align:middle line:84%
But hopefully, you can imagine,
if you had a branch that
00:02:12.540 --> 00:02:15.450 align:middle line:84%
had a ton of commits in it
and you wanted to throw away
00:02:15.450 --> 00:02:18.280 align:middle line:84%
the branch but maybe grab one
of these commits in the middle
00:02:18.280 --> 00:02:20.270 align:middle line:84%
and pull that one
in, cherry-pick makes
00:02:20.270 --> 00:02:22.870 align:middle line:90%
it really easy to do that.