It is very common for developers to commit and immediately realize that they forgot to add some files using git add
. The rest of the changes can be sent with the next commit, or, if the changes have not yet been sent to an external system, you can add the changes to the current commit. To do this, add the --amend
flag while committing:
echo 'experiment with amend' >> INFO.md
echo 'experiment with amend' >> README.md
git add INFO.md
# You forgot to prepare README.md for the commit
git commit -m 'add content to INFO.md and README.md'
[main 256de25] add content to INFO.md and README.md
1 file changed, 1 insertion(+)
git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
# You saw that you forgot to add a file. Add
git add README.md
git commit --amend
# After this command, the editor will open, waiting to enter the commit description
# Here you can change the message or quit the editor, leaving the old one behind
[main d96151a] add content to INFO.md and README.md
Date: Sat Sep 26 16:02:07 2020 -0400
2 files changed, 2 insertions(+)
git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
In reality --amend
does not add changes to an existing commit, this flag causes a commit to be rolled back (via reset) and a new commit with new data to be executed. This is why we see exactly one commit, even though the git commit
command was run twice (first one was a commit we then fix).
The --no-edit
option can be added to the git commit --amend
command to avoid opening an editor to enter a commit description. In this case, the commit description will not change.
Do it yourself
- Follow all of the steps in the lesson
- Upload the changes to GitHub
Recommended materials

Are there any more questions? Ask them in the Discussion section.
The Hexlet support team or other students will answer you.
- Article “How to Learn and Cope with Negative Thoughts“
- Article “Learning Traps“
- Article “Complex and simple programming tasks“