BM: Baca dalam Bahasa Melayu
World 10: Deep Git
Find the bug with bisect
You will learn: how to find the commit that broke something, in a few quick tests.
The problem
The shop page shows the price as RM0! Last week it said RM10. Ten commits since then. Which one broke it?
Pick one answer.
Watch
bisect: Finding the commit that broke something by testing the middle, again and again. plays “higher or lower” with your history. Give it one bad and one good commit. Git checks out the middle one for you to test.
Try it
Be the detective. Run the test, then mark the commit good or bad.
The oldest commit works. The newest one is broken. Find the first bad commit.
The test: the price in index.html must not be RM0.
87509ecAdd shop pagegooda2fb616Add a photomaybe70587efAdd opening hoursmaybe0844232Add a menu linkmaybe82a74e3Add a footermaybec35bad4Tidy up spacingmaybe30a497fAdd phone numbermaybe037d9a6Add map linkmaybe823e211Add FAQ linkmaybeaccccefUpdate footer yearbad
Tests used: 0. For 9 commits, bisect needs at most 4.
Hint
Test failed? Mark it bad. Test passed? Mark it good.Predict
Now there are 1,000 commits between good and bad. About how many tests does bisect need?
Pick one answer.
Watch
Got a test script? git bisect run sh test.sh does every step for you. Exit code 0 means good. 1 means bad.
Try it
Your turn. Start bisect, let test.sh judge, then go back home.
Hint
git bisect start HEAD HEAD~9, then git bisect run sh test.sh, then git bisect reset.Check
Put a bisect hunt in order.
First step at the top. Put these in order. Use the arrows, or drag.
- Test the commit Git checks out
- Run git bisect reset
- Run git bisect start
- Mark it good or bad, until Git names the culprit
- Mark one bad and one good commit
You did it!
You can now find the commit that broke something, fast.
Go deeper (optional)
Can’t test one commit, say it doesn’t build? git bisect skip picks a neighbour. git bisect log shows your steps. Hunting a fix, not a bug? Use git bisect old and git bisect new instead of good and bad. In bisect run, exit code 125 means skip.
Bahasa Melayu
Laman kedai tunjuk harga RM0! Minggu lepas ia RM10. Ada sepuluh commit (titik simpan) sejak itu. Yang mana merosakkannya?
Bisect main “tinggi atau rendah” dengan sejarah anda. Beri satu commit rosak (bad) dan satu yang elok (good). Git checkout commit di tengah untuk anda uji.
Jadilah detektif. Jalankan ujian, kemudian tandakan commit itu good atau bad.
Sekarang ada 1,000 commit antara good dan bad. Lebih kurang berapa ujian bisect perlukan?
Ada skrip ujian? git bisect run sh test.sh buat setiap langkah untuk anda. Kod keluar 0 maksudnya good. 1 maksudnya bad.
Giliran anda. Mulakan bisect, biar test.sh menilai, kemudian balik ke branch anda.
git bisect start HEAD HEAD~9, kemudian git bisect run sh test.sh, kemudian git bisect reset.Susun langkah memburu dengan bisect.
Kini anda boleh cari commit yang merosakkan sesuatu, dengan pantas.
You finished this before. Practice is always welcome!
Official docs: git bisect
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?