Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this movie, I want to demonstrate a soft reset. So, here's the commit log. You can see that my most recent commit was reverting this commit that was right before it. What if we wanted to undo our version, that is we wanted to get rid of this? We could revert it and revert the reversion, or what we want to do here is we want to actually rewind back in time to before I made this reversion back to this point here. So, this is the reference we're going to use. We want to rewind the HEAD back to that point so that it records from there going forward. So, what would that look like? Well, the first thing is whenever I start working with moving the HEAD pointer around, I always think it's a good idea to open up a new text file, and let's just grab the most resent commits here, we can grab the first several, no big deal, and let's just take those and paste them in here.
So now we always have these commits to refer to. If we need to get back here, we have that value recorded. Once we rewind, our log won't show it to us anymore. I'm just going to take that and put it out of the way for now. Let's first of all take a look at what the HEAD pointer points at now, git/HEAD. It points to refs/heads/master, and we saw before that, that's also a file, refs/heads/master, and it will always point to that file. So, if we ask for this, as long as we're on the master branch, it will tell us this answer, the real SHA that we're looking for is contained in this file.
So, right now it points to that 5c86ebd. If we take a look here, you can see 5c86ebd is in fact the most recent commit. So now what we want to do is a soft reset, git reset --soft, and we want to use that second commit. Again, let's just pull it up. We're going to go back to this one here. I'm going to just copy that, and there we go, we'll paste it in here. Now, it's going to move the HEAD pointer back to that point in time.
It didn't give me any kind of message there, but if I now do that same look at what it points to, refs/heads/ master, you can see it's changed. Now, it points to this other commit. And if I do git log, you'll see that the most recent commit looks like it's that one, the da3866. Now, here is what git soft does. If we do git status, you'll see that we have in our working directory and in our staging area, we have resources.html still in its most recent state, not the change that's in the Repo here, but the changes that we made since then.
This is the reverted file. Let's take a look at the contents to see, git diff --staged, and you can see this is the change we made that reverted. So it took sunglasses, sunscreen, insect repellent and moved them back to the bottom. So, it did not destructively get rid of our changes. Our changes are still here in the staging index and in the working directory. We are now ready to record a new commit if we want to, and it would just record it over essentially where that other commit was before, a lot like if we had our tape recorder, and I was saying we recorded back, recorded over the last 10 minutes of audio again.
We are essentially forgetting about that old stuff that we were doing, and making new commits from here on out. Or what we can do is we can just go back to this most recent commit and change the HEAD pointer to point back to that, get reset --soft, and put the most recent one in there. Now, if we do git log, now our version has come back again, git status, there is nothing to commit. Our working directory is clean. So all we did was basically take the HEAD pointer from pointing at this one, moved it so it's pointing at this one, and then moved it back pointing to that one again.
You can see why git reset with the soft option is the safest and least destructive, because it didn't actually remove anything at all. All it did was moved the HEAD pointer that other commit was still there, and all of our work was still maintained in the staging index and in our working directory. We didn't lose anything. In the next movie let's compare this to the mixed reset.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 100129 Viewers
56 Video lessons · 113153 Viewers
71 Video lessons · 82024 Viewers
131 Video lessons · 39354 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.