Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In the last movie we saw how to undo changes to our working directory. In this movie we're going to see how to undo changes to our staging index or in other words to un-stage things that we've staged there. Before we can get started doing that, we need to add something to our staging area. So let's open up the resources document, resources.html, and if we scroll down here, there's a list of items that it recommends that we bring on an outdoor trip. So here it is, Comfortable hiking shoes, Hat, et cetera. I'm just going to take Sunglasses and Sunscreen and cut those and move them up underneath Hat, because those are pretty important items.
So I'm going to put them near the top. Save our change, close it. Now of course, that changes in our working directory, not staged yet. So if we want to stage it we know that we do add and then resources.html. Now git status. We can see this that change has been staged there. What we want to do now is unstage that change. We don't want lose the change. We want this change to still be in our working directory. The time when you'll most often use this is if you're trying to put together a commit.
Let's say you've got five or six different files of changes that have been made,
and you're trying to assemble them into a commit in the staging area.
But then there's that extra file that you accidentally add.
So I need to unstage that one file, leave all the other ones in there, and then
I'll be ready to make my commit.
That's the real world application of how you would use this.
How do we unstage it?
Well, it gives us a little hint here in the status.
It says (use "git reset HEAD
What we're telling it is go look at the HEAD pointer. The HEAD pointer points to the last commit of the tip of the current branch, which is master. That's our current branch. Go look at that last commit and reset yourself to be the same as what that has. Very similar to what checkout did. Checkout went and checked out that file from the Repo. Here we're resetting the index to be the same as that. So we hit Return. It says Unstaged changes after the reset: is a modification--that's what the M is for--to resources.html.
If we do git status, it tells us something similar. It says that now in our working directory change is not staged. We have a modified file resources.html. If we want to add it to our staging directory, we use git add to put it there. So it's that easy. If you put something into the staging area that you don't want there, you can take it out by using git reset HEAD, and the status message will help you remember that.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97389 Viewers
61 Video lessons · 84630 Viewers
71 Video lessons · 68834 Viewers
56 Video lessons · 101294 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.
Your file was successfully uploaded.