git bisect หา commit ที่ทำให้เกิด bug ด้วย binary search
ไม่ต้องไล่ดูทีละ commit — git bisect ให้ mark good/bad แล้ว Git บอกเองว่า commit ไหนทำให้พัง
เมื่อพบ bug ที่ไม่รู้ว่าเกิดขึ้น commit ไหน:
git bisect start
git bisect bad # commit ปัจจุบันมี bug
git bisect good v1.2.0 # version นี้ยังดีอยู่
Git จะ checkout commit กลางๆ ให้ ทดสอบแล้ว mark:
git bisect good # commit นี้โอเค ยังไม่มี bug
git bisect bad # commit นี้มี bug แล้ว
ทำซ้ำจนกว่า Git จะหา commit ที่ทำให้พัง:
b3f1a2c is the first bad commit
เมื่อเสร็จ reset กลับ:
git bisect reset
สำหรับ repo ที่มีหลายร้อย commit การ bisect ทำให้หา root cause ได้ภายใน log₂(n) ขั้นตอน — 100 commits ใช้แค่ 7 ครั้ง