1
00:00:00,033 --> 00:00:04,010
In this movie, I want to
demonstrate a soft reset.

2
00:00:04,010 --> 00:00:08,000
So, here's the commit log. You can see
that my most recent commit was reverting

3
00:00:08,000 --> 00:00:10,040
this commit that was right before it.

4
00:00:10,040 --> 00:00:14,053
What if we wanted to undo our version,
that is we wanted to get rid of this?

5
00:00:14,053 --> 00:00:19,009
We could revert it and revert the
reversion, or what we want to do here is

6
00:00:19,009 --> 00:00:24,049
we want to actually rewind back in
time to before I made this reversion back

7
00:00:24,049 --> 00:00:27,067
to this point here.
So, this is the reference we're going to use.

8
00:00:27,067 --> 00:00:31,049
We want to rewind the HEAD back to
that point so that it records from

9
00:00:31,049 --> 00:00:34,058
there going forward.
So, what would that look like?

10
00:00:34,058 --> 00:00:38,008
Well, the first thing is whenever I
start working with moving the HEAD pointer

11
00:00:38,008 --> 00:00:42,033
around, I always think it's a good
idea to open up a new text file, and let's

12
00:00:42,033 --> 00:00:46,049
just grab the most resent commits here,
we can grab the first several, no big

13
00:00:46,049 --> 00:00:49,036
deal, and let's just take
those and paste them in here.

14
00:00:49,036 --> 00:00:53,014
So now we always have these commits to
refer to. If we need to get back here, we

15
00:00:53,014 --> 00:00:54,076
have that value recorded.

16
00:00:54,076 --> 00:00:58,016
Once we rewind, our log
won't show it to us anymore.

17
00:00:58,016 --> 00:01:02,015
I'm just going to take that
and put it out of the way for now.

18
00:01:02,015 --> 00:01:06,065
Let's first of all take a look at what
the HEAD pointer points at now, git/HEAD.

19
00:01:06,065 --> 00:01:10,094
It points to refs/heads/master, and
we saw before that, that's also a file,

20
00:01:10,094 --> 00:01:15,090
refs/heads/master, and it
will always point to that file.

21
00:01:15,090 --> 00:01:20,040
So, if we ask for this, as long as
we're on the master branch, it will tell us

22
00:01:20,040 --> 00:01:23,090
this answer, the real SHA that we're
looking for is contained in this file.

23
00:01:23,090 --> 00:01:27,090
So, right now it points to that 5c86ebd.

24
00:01:27,090 --> 00:01:33,029
If we take a look here, you can see
5c86ebd is in fact the most recent commit.

25
00:01:33,029 --> 00:01:41,005
So now what we want to do is a soft
reset, git reset --soft, and we want to

26
00:01:41,005 --> 00:01:44,045
use that second commit.
Again, let's just pull it up.

27
00:01:44,045 --> 00:01:46,070
We're going to go back to this one here.

28
00:01:46,070 --> 00:01:50,074
I'm going to just copy that, and
there we go, we'll paste it in here.

29
00:01:50,074 --> 00:01:54,087
Now, it's going to move the HEAD
pointer back to that point in time.

30
00:01:54,087 --> 00:02:00,000
It didn't give me any kind of message
there, but if I now do that same look at

31
00:02:00,000 --> 00:02:05,029
what it points to, refs/heads/
master, you can see it's changed.

32
00:02:05,029 --> 00:02:07,043
Now, it points to this other commit.

33
00:02:07,043 --> 00:02:16,076
And if I do git log, you'll see that the most
recent commit looks like it's that one, the da3866.

34
00:02:16,076 --> 00:02:19,014
Now, here is what git soft does.

35
00:02:19,014 --> 00:02:25,029
If we do git status, you'll see that we
have in our working directory and in our

36
00:02:25,029 --> 00:02:32,083
staging area, we have resources.html
still in its most recent state, not the

37
00:02:32,083 --> 00:02:36,046
change that's in the Repo here, but
the changes that we made since then.

38
00:02:36,046 --> 00:02:38,005
This is the reverted file.

39
00:02:38,005 --> 00:02:44,051
Let's take a look at the contents to
see, git diff --staged, and you can see

40
00:02:44,051 --> 00:02:46,090
this is the change we made that reverted.

41
00:02:46,090 --> 00:02:51,063
So it took sunglasses, sunscreen, insect
repellent and moved them back to the bottom.

42
00:02:51,063 --> 00:02:54,008
So, it did not destructively
get rid of our changes.

43
00:02:54,008 --> 00:02:58,033
Our changes are still here in the
staging index and in the working directory.

44
00:02:58,033 --> 00:03:02,090
We are now ready to record a new commit
if we want to, and it would just record

45
00:03:02,090 --> 00:03:08,036
it over essentially where that other
commit was before, a lot like if we had our

46
00:03:08,036 --> 00:03:11,036
tape recorder, and I was saying we
recorded back, recorded over the last

47
00:03:11,036 --> 00:03:12,086
10 minutes of audio again.

48
00:03:12,086 --> 00:03:16,011
We are essentially forgetting about
that old stuff that we were doing, and

49
00:03:16,011 --> 00:03:21,013
making new commits from here on out. Or
what we can do is we can just go back to

50
00:03:21,013 --> 00:03:25,079
this most recent commit and change the
HEAD pointer to point back to that, git

51
00:03:25,079 --> 00:03:31,046
reset --soft, and put the
most recent one in there.

52
00:03:31,046 --> 00:03:37,001
Now, if we do git log, now our version
has come back again, git status, there

53
00:03:37,001 --> 00:03:39,001
is nothing to commit.
Our working directory is clean.

54
00:03:39,001 --> 00:03:43,002
So all we did was basically take the
HEAD pointer from pointing at this one,

55
00:03:43,002 --> 00:03:47,060
moved it so it's pointing at this one, and
then moved it back pointing to that one again.

56
00:03:47,060 --> 00:03:51,059
You can see why git reset with the
soft option is the safest and least

57
00:03:51,059 --> 00:03:55,011
destructive, because it didn't
actually remove anything at all.

58
00:03:55,011 --> 00:03:59,078
All it did was moved the HEAD pointer
that other commit was still there, and

59
00:03:59,078 --> 00:04:03,093
all of our work was still maintained in the
staging index and in our working directory.

60
00:04:03,093 --> 00:04:05,088
We didn't lose anything.

61
00:04:05,088 --> 00:04:08,093
In the next movie let's
compare this to the mixed reset.


