World map

 

BM: Baca dalam Bahasa Melayu

World 2: Undo Magic

Fix the last commit

You will learn: how to fix the message of your last commit, or add a forgotten file.

The problem

Three commits in the repository. The newest one, Add day 2 pgae, wobbles. It has a typo.

You just made a commit. Then you spot it: “Add day 2 pgae”. Can you fix it?

Watch

The amend command types itself. Flash: the commit Add day 2 pgae is swapped for Add day 2 page.

git commit --amend swaps your last commit for a fixed one. amend: Replace your last commit with a fixed one. means “fix”. Add -m with the new message.

Try it

Build the command that fixes the typo.

Tap the pieces in the right order.

…

Try it

Now fix the typo for real.

Working folder
  • Empty
Staging area
  • Empty
Repository
  • 4 save points
  • Add day 2 pgae
  • Add style
  • Add day 1 page

Watch

day2.css waits in the box. Flash: it joins the last commit, Add day 2 page. The box is empty again.

Forgot a file? Put it in the box with git add day2.css. Then run git commit --amend --no-edit. --no-edit keeps the same message.

Predict

You amend a commit. Does it keep the same hash (commit id): A unique code that names one commit, like a1b2c3d.?

Pick one answer.

Watch

The newest commit is swapped for a new commit with a different hash. The older commits stay the same.
6d3a9b1a8feb63270a76eeb5502c

⚠️ Careful: amend swaps in a new commit. Never amend a commit you already pushed to GitHub. Your team may have the old one.

You did it!

You can now fix your last commit: the message or the files.

Go deeper (optional)

Without -m, git commit --amend opens your editor with the old message. Change it, save and close. Amend only fixes the last commit. Older commits need interactive rebase, in World 3.

day2.css is untracked. After git add and git commit --amend --no-edit, it joins the Add day 2 page commit. Terminal output: $ git status -s ?? day2.css $ git add day2.css $ git commit --amend --no-edit [main c4359e7] Add day 2 page Date: Fri Oct 30 09:04:00 2026 +0800 2 files changed, 3 insertions(+) create mode 100644 day2.css create mode 100644 day2.html $ git log --oneline c4359e7 (HEAD -> main) Add day 2 page 270a76e Add style a8feb63 Add day 1 page 6d3a9b1 Add README