Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Remove Files from Staging Before Committing

    Chris AchardChris Achard
    gitgit

    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.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: 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.

    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.

    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.

    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.

    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.