Become a member
to unlock all features

Level Up!

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


    Add More Files and Changes to a Commit Before Pushing


    To add more files to the most recent commit, we can add them to the staging area with:

    git add -A

    and then rewrite the most recent commit to include them with:

    git commit --amend -m "My new message"

    Caution: only do this BEFORE you've pushed the commits - otherwise you will be re-writing history for people who may have already pulled down the old commits.



    Become a Member to view code

    You must be a Pro 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
    orLog In




    Instructor: 0:00 I have a project with one HTML file and if I do git log oneline here, we can see that HTML file was added in this commit. Let's say I want to add a couple more files to that same commit. We can touch app.js for example and open that up. Inside of here, this will be our App.js code.

    0:20 To see that, we need to add it in the head, so we can type script, inaudible text.JavaScript. The actual files we're making here don't matter so much, but for our project, we want to have at least two files.

    0:36 Now we have the script tag added to our HTML. If we do a git status here, we can see that we have one untracked file. That's our new app.js file and one modified file, that's index.html. We want to add those to the same commit. If we do git log again, we only want one commit here.

    0:56 What we can do is actually add this to the stage, so we can do git add -a for add all. Now if we do a git status, we have changes to be committed and we can use git commit.

    1:10 If we want to add them to that same commit, this commit, then we can do --amend and we can change the git message by saying adding index.html and app.js. Now if we do a git status, we have no changes to be committed. If we do a git log oneline, all of those files were added to the same commit and it re-wrote the commit message.