Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Unstaging Changes1:51 with Jay McGavren
Staged a file, but decided you don't want to commit it? We'll show you how to unstage it.
- Let's suppose we've added a
<h1>Sale: 100% off!</h1>element in
- We can stage our changes:
git add medals.html
- Now suppose we get word that the store manager doesn't want to do the 100% off sale any more. But what can we do? We've already staged the code to announce the sale!
- If we run
git status, we'll see a help message in the output: "use
git reset HEAD <file>...to unstage"
- So, let's try that:
git reset HEAD medals.html
- If we run
git statusagain, the
medals.htmlfile will be back in the "Changes not staged for commit" section.
Now, here's the important thing. You don't have to remember this
git reset HEAD command if you don't want to. If you ever have staged changes that you want to unstage, just remember to run
git status, and it will show you the command you need to run.
If you'd like to know more about the
git reset command, check out this link: Git Reset: Atlassian Git Tutorial
Everybody makes mistakes, including long time Git users.
Git offers ways to undo almost every mistake you could possibly make.
Some of those undo operations are easier to understand than others, but
there is almost always an undo.
Let's suppose we've been asked to advertise a 100%
off sale on our site's main page.
Running git diff shows our changes.
We've added a level one header announcing our 100% off sale.
Let's stage our changes.
git add medals.html.
Now suppose we get word that the store manager doesn't
want to do the 100% off sale anymore.
Well, what can we do?
We've already staged the code to announce the sale.
Let's try running git status.
We'll see our staged medal.html file.
And the answer to our problem will be right there in the output.
It says use git reset HEAD and the file name to unstage.
So let's try that.
git reset HEAD.
HEAD needs to be in all caps, medals.html.
Now let's run git status again.
And we'll see that there's no more changes to the committed section.
Instead, the medals.html file is back in the changes not staged for commit section.
Normally, files transition from the modified to the staged state, but we've
just taken a staged file and transitioned it back to the modified state.
Now, here's the important part to remember.
You don't have to remember this git reset HEAD command if you don't want to.
If you ever have staged changes that you want to unstage,
just remember to run git status, and it will show you the command you need to run.
If you'd like to know more about the git reset command,
we'll have more info in the teacher's notes.
You need to sign up for Treehouse in order to download course files.Sign up