Add More Files and Changes to a Commit Before Pushing

Chris Achard
InstructorChris Achard
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

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.

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.

egghead
egghead
~ 34 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