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

