Focused commits & --amend

Write commits people can read

Lesson 8 of 20 · 9 min · Module 2: Everyday changes

History is written for people: your teammates, and you in six months. Small, focused commits with clear messages make it easy to read and safe to undo.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Keep each commit focused on one change
  • Write a clear summary and an explanation
  • Fix the last commit with --amend

The idea

A good commit does one thing. Its message starts with a short summary in the imperative, as if completing the sentence "This commit will…": Add a contact page, not changes. A second -m adds a paragraph that explains why. Made a typo or forgot a file in the last commit? Stage the fix and run git commit --amend: it replaces the last commit. Only do this before you share the commit.

git add menu.txt
git commit --amend -m "Add a contact page"
git commit -m "Summary" -m "Why the change was needed."

01One change, one commit

A commit should do one thing, so its message can describe it in a few words and it can be undone on its own. Mixing a new page and a colour fix in one commit makes both harder to review and to undo.

02Fix the last commit with --amend

git commit --amend replaces the last commit with a new one that includes whatever you staged since, with the message you give. The old commit is replaced, so the new one gets a new hash.

git add menu.txt
git commit --amend -m "Add a contact page"
Output
[main c04e35f] Add a contact page
 Date: Fri Oct 16 10:01:00 2026 +0000
 2 files changed, 4 insertions(+)
 create mode 100644 contact.md

03Write messages people can scan

Keep the summary short and in the imperative: Add, Fix, Remove, Update. A second -m becomes the body: explain why the change was needed, not what every line does.

git add style.css
git commit -m "Darken the footer text" -m "The light grey footer was hard to read on a white page."
git log -1
Output
[main a6f0f1d] Darken the footer text
 1 file changed, 1 insertion(+)
commit a6f0f1dc40d3d30da673de449ce2439eac2d57ec (HEAD -> main)
Author: Learner <[email protected]>
Date:   Mon Oct 19 09:02:00 2026 +0000

    Darken the footer text
    
    The light grey footer was hard to read on a white page.

Your turn

Your last commit, Add a contcat page, has a typo in its message and is missing the menu entry you added to menu.txt. It is not pushed yet. Stage menu.txt and use git commit --amend to add it and fix the message to Add a contact page. Then commit the unrelated change in style.css on its own, with the summary Darken the footer text and a second paragraph that explains why.

What the checks look for

  • The contact commit has the right message and the menu
  • The typo is gone from the history
  • The footer change is its own commit, with an explanation
  • Everything is committed
Try it in the editor →

Take this with you

Small, focused commits with clear messages make history useful; --amend polishes the last one before you share it.

Go a little further

Use git commit --amend --no-edit to add a forgotten file to the last commit without changing its message.

Learn Git & GitHub for free

20 short lessons with real code and instant checks.

See the whole course →