Remove Files from Staging Before Committing

Chris Achard
InstructorChris Achard
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

If you've added files to the staging area (the Index) accidentally - you can remove them using git reset.

We'll first add a file to staging, but then back it out with:

git reset HEAD filename

in order to pull it back to the working directory, so it doesn't end up in a commit when we don't want it to.

Instructor: [00:00] Now, let's add another JavaScript file called limb.js and inside of limb.js, we can say that, "This is my limb file." Then, we want to do a Git status to see that it's on tract. Let's add the limb JS file and we're about to commit.

[00:19] We have some changes to be committed, but then we maybe realize that we don't actually want to commit them. We've added it to staging, but we don't actually want to commit this limb file at all. The good news is that Git tells us how to fix it right here.

[00:33] We can do a Git reset HEAD and then the file name. Let's figure out first what this head is. If we do a Git log one line, then we can see that head is a pointer to a branch and that branch is just a pointer to the commit specified by this hash.

[00:52] If we say git reset HEAD, then give it a file, it will reset this file back to what it was in this commit, which means it won't exist. We can do git reset HEAD lib.js. Now, if we do a git status, we can see that it's untracked. It's removed from the staging area because it doesn't exist in this commit.

[01:16] Now, if we want to get rid of it entirely, we can remove lib.js. If we do a git status, then we're back to normal. We can just have our index.html and our app.js. The lib.js file is gone.

egghead
egghead
~ 14 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today