BM: Baca dalam Bahasa Melayu
World 11: Rescue Center
I committed on the wrong branch
You will learn: how to move a commit to the branch it belongs on.
The problem
Oops. You committed your about page on main. It was meant for its own branch. This happens to everyone. Here’s the safe way out.
Try it
First question: did you push it? Not yet. So which fix fits?
Pick one answer.
Watch
git branch about sticks a new label on your commit. git reset --hard HEAD~1 moves main back one step. Your commit stays safe on about.
Try it
Your turn. Move the commit to a branch called about. Then switch to it.
Hint
Typegit branch about, then git reset --hard HEAD~1, then git switch about.Predict
Careful: reset --hard also wipes changes you haven’t committed. When is it safe here?
Pick one answer.
Check
What if you had pushed it? Pick the fix for each case.
Drag a card into a box. Or tap the card, then tap the box.
You did it!
You can now move a commit to the branch it belongs on.
Go deeper (optional)
Does the right branch exist already? Switch to it and run git cherry-pick main to copy the commit. Then take it off main with git reset --hard HEAD~1. Already pushed? Run git revert HEAD on main and push. Then git switch -c about and git cherry-pick main~1 bring your work over.
Bahasa Melayu
Alamak. Anda commit (titik simpan) halaman about di main. Sepatutnya ia dalam branch (cabang) sendiri. Ini berlaku pada semua orang. Ini cara selamat untuk keluar.
Soalan pertama: dah push? Belum lagi. Jadi, cara baiki yang mana sesuai?
git branch about lekatkan label baru pada commit anda. git reset --hard HEAD~1 undurkan main satu langkah. Commit anda kekal selamat di about.
Giliran anda. Pindahkan commit ke branch bernama about. Kemudian tukar ke branch itu.
git branch about, kemudian git reset --hard HEAD~1, kemudian git switch about.Hati-hati: reset --hard juga padam perubahan yang belum di-commit. Bila ia selamat di sini?
Kalau anda dah push? Pilih cara baiki untuk setiap keadaan.
Kini anda boleh pindahkan commit ke branch yang sepatutnya.
You finished this before. Practice is always welcome!
Official docs: git branch · git reset · git cherry-pick · git revert
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?