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

