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

> Forgot to add a file to your last Git commit? Learn how to use git commit --amend to stage the missing file and optionally fix the commit message.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2024-04-18 | Topics: [Git](https://flaviocopes.com/tags/git/) | Canonical: https://flaviocopes.com/git-what-if-you-forgot-to-add-a-file-to-a-commit/

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:

```text
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:

```text
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.

For this and other Git mistakes, I made a free [Git recovery tool](https://flaviocopes.com/tools/git-recovery/) that gives you step-by-step commands to get out of trouble.
