World map

 

BM: Baca dalam Bahasa Melayu

World 11: Rescue Center

I forgot a file

You will learn: how to add a forgotten file to your last commit.

The problem

A commit, Add day 2 page, sits in the repository. day2.css glows on your desk, left behind.

You committed your day 2 page. But its style file is still on your desk! This happens to everyone. Here’s the safe way out.

Try it

You haven’t pushed yet. What’s the neatest fix?

Pick one answer.

Try it

First, git add day2.css puts the file in the box. Now build the command that tucks the box into your last commit.

Tap the pieces in the right order.

…

Try it

Now do it for real. Add day2.css to the last commit.

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

Check

After the amend, git show --stat lists day2.css and day2.html in the Add day 2 page commit. Terminal output: $ git add day2.css $ git commit --amend --no-edit [main e8f3496] 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 show --stat commit e8f3496b32bd3299b97ab05d2e6ea197d63768fd (HEAD -> main) Author: You <you@example.com> Date: Fri Oct 30 09:04:00 2026 +0800 Add day 2 page day2.css | 1 + day2.html | 2 ++ 2 files changed, 3 insertions(+)

Check with git show --stat. Both files sit in one commit. Same message as before.

Predict

New story: you had pushed the commit already. What now?

Pick one answer.

You did it!

You can now add a forgotten file to your last commit.

Go deeper (optional)

Amend makes a brand-new commit with a new hash. That is why it’s only for commits you haven’t pushed. Forgot a file several commits ago? Just commit it now with a clear message. Simple wins.