Skip to content

Git, what if you forgot to add a file to a commit?

New Course Coming Soon:

Get Really Good at Git

This post is part of my pre-launch series for my upcoming course Get Really Good at Git launching on May 21. If this post helps you, the course will be a great fit for you, to help you get a much better understanding of Git, reduce your frustrations with it, and figure out the good parts of this incredibly useful tool

This is common, you commit something but realize you forgot to include a specific file, maybe because you forgot to run git add to stage it.

No worries - you can use git commit --amend to take the previous commit, “undo” it, apply all that’s currently staged, and then commit again:

git add file-forgotten.txt
git commit --amend

If you need, you can also change the commit message while you’re adding the file, using the -m option:

git commit --amend -m "New commit message"

As with any operation that rewrites the history, I would only use it if you are working on a local branch, or if you are 100% sure no one else is working on the same branch.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!

Here is how can I help you: