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. 0:00 Don't worry, 0:03 Git offers ways to undo almost every mistake you could possibly make. 0:04 Some of those undo operations are easier to understand than others, but 0:08 there is almost always an undo. 0:12 Let's suppose we've been asked to advertise a 100% 0:14 off sale on our site's main page. 0:17 Running git diff shows our changes. 0:19 We've added a level one header announcing our 100% off sale. 0:22 Let's stage our changes. 0:25 git add medals.html. 0:28 Now suppose we get word that the store manager doesn't 0:33 want to do the 100% off sale anymore. 0:35 Well, what can we do? 0:38 We've already staged the code to announce the sale. 0:39 Let's try running git status. 0:42 We'll see our staged medal.html file. 0:46 And the answer to our problem will be right there in the output. 0:49 It says use git reset HEAD and the file name to unstage. 0:52 So let's try that. 0:57 git reset HEAD. 0:58 HEAD needs to be in all caps, medals.html. 1:02 Now let's run git status again. 1:07 And we'll see that there's no more changes to the committed section. 1:10 Instead, the medals.html file is back in the changes not staged for commit section. 1:14 Normally, files transition from the modified to the staged state, but we've 1:21 just taken a staged file and transitioned it back to the modified state. 1:26 Now, here's the important part to remember. 1:30 You don't have to remember this git reset HEAD command if you don't want to. 1:33 If you ever have staged changes that you want to unstage, 1:37 just remember to run git status, and it will show you the command you need to run. 1:41 If you'd like to know more about the git reset command, 1:46 we'll have more info in the teacher's notes. 1:48
You need to sign up for Treehouse in order to download course files.Sign up