0:00:00.206,0:00:04.616
Git reset is the command that allows you[br]to shape history in your repository.
0:00:04.616,0:00:07.945
Whether you're undoing some changes[br]or crafting your commits differently,
0:00:07.945,0:00:09.401
this is the command for you.
0:00:09.651,0:00:11.241
♪ (bossa music) ♪
0:00:14.751,0:00:18.153
Welcome to the episode of Git and GitHub Foundations on the reset command.
0:00:18.538,0:00:21.560
This command has a lot of power,[br]and a lot of modes.
0:00:21.560,0:00:24.512
Yeah, there's going to be three modes[br]we're going to be working with here.
0:00:24.512,0:00:28.236
There's going to be soft;[br]mixed, or the default; and hard.
0:00:28.555,0:00:30.587
♪ (music) ♪
0:00:31.032,0:00:32.921
these adjectives are pretty descriptive,
0:00:33.088,0:00:35.513
starting with the one[br]that's the default, mixed.
0:00:35.830,0:00:39.648
It alters both the history[br]and the working directory.
0:00:39.998,0:00:41.708
So mixed, both things.
0:00:41.898,0:00:44.427
And soft is going to take[br]one or multiple commits
0:00:44.427,0:00:47.179
and put all of their changes[br]back into the staging area
0:00:47.179,0:00:50.048
to allow you to continue to craft[br]a new commit out of that.
0:00:50.433,0:00:53.279
Hard, on the other hand,[br]is a destructive operation
0:00:53.279,0:00:55.893
that's meant to erase things[br]that you no longer wish to keep.
0:00:56.212,0:00:59.552
So with all three of these in our stable,
0:00:59.552,0:01:01.430
let's look at mixed first.
0:01:03.475,0:01:05.173
Mixed is the recommendation
0:01:05.173,0:01:07.242
that gets most often shown[br]to new Git users
0:01:07.271,0:01:09.444
because it shows up[br]in the status command.
0:01:09.609,0:01:12.391
When you have changes in the staging area[br]and you say git status,
0:01:12.621,0:01:14.493
we see a Git reset head.
0:01:14.493,0:01:17.046
That allows us to take those changes[br]out of the staging area
0:01:17.046,0:01:18.875
and put them back[br]into the working directory
0:01:18.875,0:01:20.371
with the mixed option.
0:01:20.672,0:01:23.379
Soft is the way[br]that I take some changes
0:01:23.379,0:01:25.706
that might have gotten[br]too granular in nature.
0:01:26.033,0:01:27.869
One, two, three, four, five commits
0:01:27.869,0:01:30.846
that I then realize all belong[br]in one transaction,
0:01:30.846,0:01:36.907
and to bring them all together[br]by a git reset --soft HEAD~5
0:01:36.907,0:01:38.610
the most recent five commits.
0:01:38.835,0:01:41.100
So with that command of using soft
0:01:41.100,0:01:42.696
you can take[br]all five of those commits
0:01:42.696,0:01:46.285
and kind of squash them down[br]into the staging area as one commit.
0:01:46.665,0:01:48.765
Pretty useful for reshaping history,
0:01:48.765,0:01:51.295
but reshaping history goes[br]to the far end of the spectrum
0:01:51.295,0:01:54.630
to throw away commits[br]that just don't add value.
0:01:54.877,0:01:57.748
You don't want to send them,[br]transmit them, or share them with others.
0:01:57.922,0:01:59.521
That's where hard comes into play.
0:01:59.521,0:02:01.853
If you completely want to throw away[br]some of your work,
0:02:01.853,0:02:04.710
maybe you're trying out some change[br]that just didn't work out,
0:02:04.710,0:02:08.061
you can use the git reset --hard[br]to throw those commits away completely.
0:02:08.606,0:02:11.268
People might ask, then why[br]would you make a commit?
0:02:11.268,0:02:13.971
But Git provides you[br]a really nice safety net
0:02:13.971,0:02:17.078
through the reflog command[br]that we'll look at in a future episode
0:02:17.078,0:02:20.488
that motivates you to make[br]checkpoints with commits,
0:02:20.488,0:02:22.653
and knowing that you have[br]hard at your disposal,
0:02:22.653,0:02:25.180
you can clean that history up[br]anytime you like.
0:02:25.850,0:02:27.464
♪ (music) ♪
0:02:27.760,0:02:32.178
There is one other cousin command[br]that is often talked about with reset
0:02:32.178,0:02:34.152
and that's the checkout command.
0:02:34.152,0:02:37.702
The checkout command[br]is of a different granularity than reset,
0:02:37.702,0:02:41.266
which typically operates[br]on the entire history of a repository.
0:02:41.703,0:02:45.395
Checkout is focused more[br]on a directory or a file level precision.
0:02:45.756,0:02:49.287
Instead of undoing or changing[br]an entire commit,
0:02:49.287,0:02:52.710
we can go back in history[br]to a specific file at a commit
0:02:52.710,0:02:57.297
and pull that file and its version[br]back to our current working directory.
0:02:57.685,0:03:01.234
Clear communication is the goal[br]of all Git repository history.
0:03:01.487,0:03:06.022
So whether it's git reset --hard,[br]reset --soft, reset --mixed,
0:03:06.022,0:03:08.145
or the more precise checkout command,
0:03:08.145,0:03:12.837
use these to provide clear intent[br]about your changes to your colleagues.
0:03:13.284,0:03:15.976
Git reset is a tool that can be[br]a little bit intimidating
0:03:15.976,0:03:17.235
to new users of Git.
0:03:17.434,0:03:20.184
But it can be a powerful tool[br]to have at your disposal
0:03:20.184,0:03:22.473
for crafting beautiful repository history.
0:03:24.181,0:03:28.029
Thanks for watching another episode[br]of Git and GitHub Foundations on reset.
0:03:28.029,0:03:31.687
As always, don't forget to subscribe[br]to any of our channels on the side her.
0:03:31.687,0:03:33.811
Questions or comments?[br]Put those down below
0:03:33.811,0:03:36.401
or check out one[br]of our other educational topics
0:03:36.401,0:03:38.523
on Git and GitHub[br]here at the bottom.
0:03:38.789,0:03:40.658
♪ (music) ♪