1
00:00:00,000 --> 00:00:03,990
In the last two movies we've taken a look at a soft reset and a mixed reset.

2
00:00:04,000 --> 00:00:08,990
In this movie we're going to take a look at the hard reset, or a Git reset

3
00:00:09,000 --> 00:00:09,990
using the hard option.

4
00:00:10,000 --> 00:00:14,990
Now, of the three this is the most destructive, because all three of them rewind

5
00:00:15,000 --> 00:00:20,990
the HEAD pointer to point to another commit, but the other two leave the files

6
00:00:21,000 --> 00:00:24,990
either in our staging index or in our working directory so that we then have

7
00:00:25,000 --> 00:00:28,990
those changes still at hand ready to remake those commits.

8
00:00:29,000 --> 00:00:29,990
The hard reset doesn't do that.

9
00:00:30,000 --> 00:00:35,990
Hard reset makes our staging index and our working directory exactly match the repo.

10
00:00:36,000 --> 00:00:38,990
It throws out everything that happened after that.

11
00:00:39,000 --> 00:00:42,990
Those commits are not just sitting there waiting for us to recommit, we're now

12
00:00:43,000 --> 00:00:46,990
essentially rewound back to that previous commit.

13
00:00:47,000 --> 00:00:49,990
That makes it the easiest way for you to lose data.

14
00:00:50,000 --> 00:00:54,990
The main time that you want to use a git reset hard is when things have really

15
00:00:55,000 --> 00:00:57,990
just gotten out of hand in your working directory, they're just completely out

16
00:00:58,000 --> 00:00:59,990
of sync, that's what git reset hard is great at.

17
00:01:00,000 --> 00:01:03,990
It just says, you know what, I don't want everything that happened after that.

18
00:01:04,000 --> 00:01:07,990
I really wish I could go back and just do a hard reset to this point and then

19
00:01:08,000 --> 00:01:10,990
move forward from there. So let's try it.

20
00:01:11,000 --> 00:01:14,990
Again, just like on the other two, grab some of these commits and put those into

21
00:01:15,000 --> 00:01:19,990
a new text file, so then we'll have these references to these later commits if

22
00:01:20,000 --> 00:01:21,990
we decide that we want to go back to them.

23
00:01:22,000 --> 00:01:25,990
And the commit that we're going to roll back to is going to be the same one,

24
00:01:26,000 --> 00:01:27,990
we'll just go back to that right there.

25
00:01:28,000 --> 00:01:33,990
So it's git reset with the hard option to this SHA right here so that's going to

26
00:01:34,000 --> 00:01:37,990
rewind back and undo the revert commit that we made.

27
00:01:38,000 --> 00:01:43,990
So it tells us HEAD is now at this point, and it gives us the name of that.

28
00:01:44,000 --> 00:01:47,990
If we take a look at the log, we'll see that in fact that's what it points to,

29
00:01:48,000 --> 00:01:49,990
that's the most recent commit.

30
00:01:50,000 --> 00:01:53,990
And if we do git status, you'll see that it tells us our working directory is

31
00:01:54,000 --> 00:01:56,990
clean, there's no trace of that file.

32
00:01:57,000 --> 00:02:01,990
There is no trace of the changes that we made to resources.html.

33
00:02:02,000 --> 00:02:05,990
Now, we can at this point do our revert again if we wanted to, if we wanted to

34
00:02:06,000 --> 00:02:09,990
do it over, or if we just thought we wanted to do something different, we've now

35
00:02:10,000 --> 00:02:13,990
essentially rewound our project back to this previous point in time.

36
00:02:14,000 --> 00:02:17,990
I said that it throws everything away, that's not entirely true, it doesn't

37
00:02:18,000 --> 00:02:20,990
throw everything away, it's just not sitting here waiting for us to make those

38
00:02:21,000 --> 00:02:22,990
commits, it's not at hand.

39
00:02:23,000 --> 00:02:27,990
However, those old commits are still there, we can still move our HEAD back to

40
00:02:28,000 --> 00:02:29,990
this later point in time.

41
00:02:30,000 --> 00:02:37,990
So let's do that, git reset --hard, and we'll put in the later commit again, it

42
00:02:38,000 --> 00:02:41,990
now moved it up there, that git object was still there, it's still sitting there

43
00:02:42,000 --> 00:02:46,990
in the git folders, it had just moved the HEAD pointer away from it.

44
00:02:47,000 --> 00:02:49,990
At some point if we hadn't done anything with it, it would have gotten garbage

45
00:02:50,000 --> 00:02:53,990
collected and thrown away, that would have been a long ways down the line.

46
00:02:54,000 --> 00:02:58,990
It would have hung on to it for a while just to make sure that we didn't want to go back to it.

47
00:02:59,000 --> 00:03:03,990
But it wouldn't have been easy to go back to it if we didn't record this reference right here.

48
00:03:04,000 --> 00:03:06,990
We wouldn't have those changes in our working directory, and we wouldn't know

49
00:03:07,000 --> 00:03:10,990
the name of the commit that would take us back there to get to it.

50
00:03:11,000 --> 00:03:14,990
So unlike the other two examples that we did with reset, let's go ahead and take

51
00:03:15,000 --> 00:03:16,990
the additional step of making a new commit here.

52
00:03:17,000 --> 00:03:20,990
So let's do git log, and instead of just reverting this commit, let's rewind

53
00:03:21,000 --> 00:03:23,990
back here before we even rearrange the items the first time.

54
00:03:24,000 --> 00:03:29,990
So I'm going to use this 2907 as the SHA, let's do git reset --hard, and let's

55
00:03:30,000 --> 00:03:35,990
rewind back to that point. So now it's rewound us back to git log.

56
00:03:36,000 --> 00:03:42,990
You can see we're back to removed contractions from page text, git status, you

57
00:03:43,000 --> 00:03:45,990
can see that there's nothing in my staging index or working directory.

58
00:03:46,000 --> 00:03:50,990
And if we open up resources.html, and we scroll down to that list, you'll see

59
00:03:51,000 --> 00:03:53,990
that it's back in its original state.

60
00:03:54,000 --> 00:03:57,990
So it essentially did the reversion by allowing us to rewind.

61
00:03:58,000 --> 00:04:00,990
Let's say that we now want to make additional changes though and go forward.

62
00:04:01,000 --> 00:04:06,990
Let's say that we want to just move sunglasses up here after hat, put it right

63
00:04:07,000 --> 00:04:12,990
in front of hat, and then I'll save it, close it, git status. Let's do git

64
00:04:13,000 --> 00:04:16,990
commit, and we're going to use the -a option, which is going to commit all of my

65
00:04:17,000 --> 00:04:23,990
changes all at once with the message, and we're going to say "Moved sunglasses

66
00:04:24,000 --> 00:04:29,990
higher in list of suggested outdoor items".

67
00:04:30,000 --> 00:04:35,990
So now it's made my new commit. Nothing in my directory. Git log.

68
00:04:36,000 --> 00:04:37,990
Now I've put a new commit here.

69
00:04:38,000 --> 00:04:43,990
So now, after this one comes this one, I've essentially rewound in time and started recording.

70
00:04:44,000 --> 00:04:49,990
And now my HEAD pointer points to this new commit, and all my future commit will just come off of that.

71
00:04:50,000 --> 00:04:52,990
Those other commits that we made, they're now just lost, they're sitting there

72
00:04:53,000 --> 00:04:56,990
abandoned in the git folder and they will eventually get garbage collected.

73
00:04:57,000 --> 00:05:01,990
So that's how you use the three different forms of reset, soft, mix, and hard.

74
00:05:02,000 --> 00:05:07,990
Again, just be careful when you use them, because they do allow you to overwrite data.

75
00:05:08,000 --> 00:05:18,000



