BM: Baca dalam Bahasa Melayu
World 2: Undo Magic
Reset lab
You will learn: how git reset moves your branch back, in three modes.
The problem
Your last commit was a mistake. It is only on your laptop. Can you step back one commit?
Watch
reset: Move your branch back to an older commit. moves your branch back. HEAD~1 means “one commit before HEAD”. The mode decides where the undone changes go.
Try it
Try all three modes. Watch where the changes land.
Pick a reset type
- Empty
- Empty
- 4 save points
- Add day 2 entry
- Add style
- Add day 1 page
You tried 0 of 3.
Hint
Soft, then mixed, then hard. Each one runsgit reset --<mode> HEAD~1.Predict
You want to redo the commit. The changes should stay in the box. Which mode?
Pick one answer.
Watch
⚠️ Danger: --hard wipes the changes from your files too. Edits you never committed are lost for good. Use it only when you’re sure.
Try it
Undo the last commit. Keep the changes in your folder.
- Empty
- Empty
- 4 save points
- Add day 2 entry
- Add style
- Add day 1 page
Hint
Typegit reset HEAD~1, then press Enter.Check
You type git reset HEAD~1 with no mode. Where do the changes go?
Pick one answer.
You did it!
You can now move your branch back, in three different ways.
Go deeper (optional)
HEAD~2 goes back two commits. You can also reset to a hash from git log --oneline. Reset rewrites history. Only reset commits that are still just on your computer. Shared commits need revert (next lesson).
Bahasa Melayu
Commit (titik simpan) terakhir anda satu kesilapan. Ia hanya ada dalam laptop anda. Boleh undur satu langkah?
Reset (undur) gerakkan branch (jalan cerita) anda ke belakang. HEAD~1 maksudnya “satu commit sebelum HEAD”. Mod yang anda pilih tentukan ke mana perubahan pergi.
Cuba ketiga-tiga mod. Tengok ke mana perubahan pergi.
git reset --<mode> HEAD~1.Anda mahu buat semula commit itu. Perubahan patut kekal dalam kotak. Mod mana?
⚠️ Bahaya: --hard padam perubahan dalam fail anda juga. Suntingan yang belum di-commit hilang terus. Guna hanya bila anda pasti.
Undurkan commit terakhir. Kekalkan perubahan dalam folder anda.
git reset HEAD~1, kemudian tekan Enter.Anda taip git reset HEAD~1 tanpa mod. Ke mana perubahan pergi?
Kini anda boleh undurkan branch anda, dengan tiga cara berbeza.
You finished this before. Practice is always welcome!
Official docs: git reset · Revision names (HEAD~1)
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?