BM: Baca dalam Bahasa Melayu
World 2: Undo Magic
Undo safely with revert
You will learn: how to undo a shared commit without rewriting history.
The problem
Two commits ago, you made the heading blink. Everyone hates it. Your team already has that commit.
Watch
revert: Make a new commit that undoes an old one. adds a new commit that does the opposite. The bad commit stays in history. Nothing is erased.
Try it
Tap the commit that made the heading blink.
Tap the bad commit.
Hint
Read the messages. One of them says “blink”.Predict
You revert “Make heading blink”. Is your day 2 entry still there?
Pick one answer.
Try it
Now revert the blink commit in the terminal.
Hint
HEAD~1 is the commit just before the newest one.Check
Your bad commit is already on GitHub. Which undo do you pick?
Pick one answer.
You did it!
You can now undo a shared commit without breaking anyone’s history.
Go deeper (optional)
In real Git, git revert opens your editor with a ready message. Save and close it. --no-edit skips the editor. Did later commits change the same lines? Then you get a conflict. Conflicts come in World 3.
Bahasa Melayu
Dua commit (titik simpan) lalu, anda buat tajuk berkelip-kelip. Semua orang tak suka. Pasukan anda pun dah ada commit itu.
Revert (batalkan) tambah commit baru yang buat sebaliknya. Commit yang teruk kekal dalam sejarah. Tiada apa yang dipadam.
Tekan commit yang buat tajuk berkelip.
Anda revert “Make heading blink”. Adakah catatan day 2 anda masih ada?
Sekarang revert commit blink itu dalam terminal.
HEAD~1 ialah commit sebelum yang terbaru.Commit teruk anda dah ada di GitHub. Undur yang mana anda pilih?
Kini anda boleh undur commit yang dikongsi tanpa rosakkan sejarah sesiapa.
You finished this before. Practice is always welcome!
Official docs: git revert · git log
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?