Menu
Coddy logo textTech

Amend The Last Commit

Part of the Version Control section of Coddy's Terminal journey — lesson 42 of 58.

If you just created a commit and immediately realize the message is wrong, or you forgot to include a file, you can rewrite that commit with:

git commit --amend -m "New message"

This replaces the most recent commit with a new one that has your updated message and includes whatever is currently staged.

To add a forgotten file to the previous commit, stage it first, then amend without changing the message:

git add forgotten.txt
git commit --amend --no-edit

The --no-edit flag keeps the existing message.

One catch: amending creates a brand-new commit (with a new ID), even though it looks like an edit. Only amend commits you have not shared with anyone yet, or you will confuse collaborators who already have the old version.

challenge icon

Challenge

Easy

The folder contains app.py. Initialize the repo, stage and commit the file with the message Inital commit (intentional typo).

Amend the commit to fix the message to Initial commit, then print the latest commit subject using git log -1 --pretty=%s.

Cheat sheet

Fix the most recent commit message with --amend:

git commit --amend -m "New message"

Add a forgotten file to the previous commit without changing the message:

git add forgotten.txt
git commit --amend --no-edit

Amending creates a new commit ID — only amend commits not yet shared with others.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Version Control