Skip to content

git bisect #23

@rootEnginear

Description

@rootEnginear

เวลา dev ไปเรื่อยๆ แล้วฟีเจอร์ใดฟีเจอร์หนึ่งระเบิด ถ้ามีอยู่ไม่กี่ commit เราอาจจะยังพอไล่ checkout ได้ แต่ถ้ามีจำนวน commit มากๆ เราสามารถใช้วิธีการ bisect เพื่อหา commit ที่ทำเจ๊งได้

  1. git bisect start — เริ่มการ bisect
  2. git bisect good <sha> — บอกว่า commit ตัวไหนที่ยังไม่พัง ตรงนี้อาจจะดูตัวที่ test ผ่าน/build ผ่านล่าสุด ก็ได้
  3. git bisect bad <sha> — บอกว่า commit ไหนพัง จะใส่ commit ล่าสุดก็ได้
  4. git จะเริ่ม binary search หาว่า commit ไหนพัง
    • ถ้า commit ที่ git หยิบมาดี: git bisect good
    • ถ้า commit ที่ git หยิบมาเจ๊ง: git bisect bad
  5. ทำวนไปเรื่อยๆ จนกระทั่ง good กับ bad มาติดกัน — ตัวที่เป็น bad คือจุดที่เริ่มพัง
  6. ออกด้วย git bisect reset

ทริคจาก @suphon-t

ถ้าสมมติมี command ที่เราจะทดสอบว่าตายตอนไหน สามารถใช้คำสั่ง git bisect run <command> ได้ เช่น git bisect run pnpm build

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions