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
You just made a commit. Then you spot it: “Add day 2 pgae”. Can you fix it?
Watch
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.
Hint
Start withgit commit. The message comes last.Try it
Now fix the typo for real.
- Empty
- Empty
- 4 save points
- Add day 2 pgae
- Add style
- Add day 1 page
Hint
Typegit commit --amend -m "Add day 2 page", then press Enter.Watch
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
⚠️ 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.
Bahasa Melayu
Anda baru buat commit (titik simpan). Kemudian anda nampak: “Add day 2 pgae”. Boleh baiki tak?
git commit --amend tukar commit terakhir anda dengan versi yang dibaiki. Amend (pinda) maksudnya “baiki”. Tambah -m dengan mesej baru.
Bina arahan yang membaiki salah taip itu.
git commit. Mesej datang paling akhir.Sekarang baiki salah taip itu betul-betul.
git commit --amend -m "Add day 2 page", kemudian tekan Enter.Terlupa satu fail? Masukkan ke dalam kotak dengan git add day2.css. Kemudian jalankan git commit --amend --no-edit. --no-edit kekalkan mesej yang sama.
Anda amend satu commit. Adakah hash (id commit) kekal sama?
⚠️ Awas: amend tukar ke commit baru. Jangan amend commit yang dah di-push (dihantar) ke GitHub. Pasukan anda mungkin ada versi lama.
Kini anda boleh baiki commit terakhir anda: mesej atau failnya.
You finished this before. Practice is always welcome!
Official docs: git commit · git add
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?