BM: Baca dalam Bahasa Melayu
World 11: Rescue Center
I'm in detached HEAD
You will learn: how to leave a detached HEAD without losing commits.
The problem
Git says HEAD is detached. Sounds scary! It only means HEAD sits on a commit, not on a branch. This happens to everyone.
Watch
You made a commit while detached. Leave now, and it gets left behind. No branch holds it.
Try it
You want to keep that commit. What do you do first?
Pick one answer.
Try it
Keep your commit. Make a branch called new-title, right here.
Hint
Typegit switch -c new-title, then press Enter.Predict
New story: you only looked around. No new commits. How do you get home?
Pick one answer.
You did it!
You can now leave a detached HEAD without losing commits.
Go deeper (optional)
Already left, and the commit is gone? The reflog remembers. Right after leaving, git branch new-title HEAD@{1} brings it back. Git also prints the commit’s hash when you leave. git branch new-title plus that hash works too.
Bahasa Melayu
Git kata HEAD terlerai (detached). Bunyinya menakutkan! Maksudnya cuma HEAD duduk atas commit (titik simpan), bukan atas branch (cabang). Ini berlaku pada semua orang.
Anda buat commit semasa terlerai. Keluar sekarang, dan ia tertinggal. Tiada branch yang pegang.
Anda nak simpan commit itu. Apa yang anda buat dulu?
Simpan commit anda. Buat branch bernama new-title, di sini juga.
git switch -c new-title, kemudian tekan Enter.Cerita baru: anda cuma tengok-tengok. Tiada commit baru. Macam mana nak balik?
Kini anda boleh keluar dari HEAD terlerai tanpa hilang commit.
You finished this before. Practice is always welcome!
Official docs: git switch · git branch · git reflog
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?