BM: Baca dalam Bahasa Melayu
World 11: Rescue Center
Undo my last commit
You will learn: the safe undo for your last commit, pushed or not.
The problem
You committed day 2 too soon. It isn’t ready yet. Can you take the commit back? Yes! This happens to everyone.
Try it
You haven’t pushed. You want to keep the changes. Which undo?
Pick one answer.
Watch
git reset --soft HEAD~1 takes the last commit back. Nothing is lost: the changes sit in the box, ready for later.
Try it
Take back the day 2 commit. Keep the changes in the box.
- Empty
- Empty
- 4 save points
- Add day 2 entry
- Add style
- Add day 1 page
Hint
Typegit reset --soft HEAD~1, then press Enter.Predict
New story: the commit is pushed. Teammates have it. Which undo is safe?
Pick one answer.
Try it
Undo the pushed commit the safe way. Then push the undo.
Hint
Typegit revert HEAD, then git push.You did it!
You can now undo your last commit, pushed or not.
Go deeper (optional)
--soft keeps changes in the box. Plain git reset HEAD~1 keeps them on your desk, out of the box. --hard wipes them, so use it only for changes you truly don’t want. The commit itself stays findable. See “Reflog, your safety net” in World 2.
Bahasa Melayu
Anda commit (titik simpan) hari 2 terlalu awal. Ia belum siap. Boleh tarik balik commit itu? Boleh! Ini berlaku pada semua orang.
Anda belum push. Anda nak simpan perubahan itu. Undur yang mana?
git reset --soft HEAD~1 tarik balik commit terakhir. Tiada yang hilang: perubahan duduk dalam kotak, sedia untuk nanti.
Tarik balik commit hari 2. Simpan perubahan dalam kotak.
git reset --soft HEAD~1, kemudian tekan Enter.Cerita baru: commit itu dah push. Kawan sepasukan dah ada. Undur yang mana selamat?
Undur commit yang dah push dengan cara selamat. Kemudian push commit undur itu.
git revert HEAD, kemudian git push.Kini anda boleh undur commit terakhir, dah push atau belum.
You finished this before. Practice is always welcome!
Official docs: git reset · git revert
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?