Bisect: ตามหาคอมมิตที่มีปัญหา
ใช้ git bisect ค้นหาแบบทวิภาคผ่านประวัติ เพื่อระบุคอมมิตที่ทำให้เกิดบั๊กได้อย่างแม่นยำ แม้ต้องตรวจสอบคอมมิตหลายร้อยรายการ
Bisect: ตามหาคอมมิตที่มีปัญหา เป็นบทเรียน Git Advanced: Monorepo, Submodules & Workflows ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Git Advanced: Monorepo, Submodules & Workflows และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Git Advanced: Monorepo, Submodules & Workflows มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
The Needle in the Haystack
A bug hides somewhere in your last 200 commits. git bisect runs a binary search through history, halving the suspect range with each test.
How Binary Search Helps
Checking 200 commits linearly means 200 tests. Binary search needs only about log2(200) ≈ 8 — bisect narrows the culprit dramatically faster.
Starting a Bisect
Kick off a session with git bisect start. From there Git walks you through marking commits as good or bad.
git bisect startMarking Good and Bad
Tell Git where the bug exists (bad) and an older commit where it didn't (good). That bounds the search range.
git bisect bad HEAD
git bisect good v1.2.0Testing Each Checkout
Git checks out the midpoint commit. You test it and report good or bad, and Git picks the next midpoint accordingly.
git bisect good
# or
git bisect badReaching the Culprit
After a few rounds, Git names the first bad commit — its hash, author, and message — the exact change that introduced the bug.
Ending the Session
Always finish with git bisect reset. It returns you to your starting branch and clears the bisect state.
git bisect resetAutomating with a Script
If you can test the bug programmatically, git bisect run ./test.sh automates the whole search — exit 0 means good, non-zero means bad.
git bisect run ./test.shThe Skip Escape Hatch
Hit a commit you can't test (it won't build)? git bisect skip tells Git to try a nearby commit instead.
git bisect skipReviewing the Log
git bisect log saves or replays the decisions you made — useful for documenting how you found a bug or resuming a session later.
git bisect logBest Practices
For reliable bisects: have a clear, reproducible test, keep commits small and atomic, and automate with git bisect run whenever you can.
Quick Check
Test your bisect knowledge.
Recap
Recap: git bisect start, mark good and bad, test each midpoint to halve the range, automate with run, skip the untestable, and reset when done.
คำถามที่พบบ่อย
บทเรียน “Bisect: ตามหาคอมมิตที่มีปัญหา” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “Bisect: ตามหาคอมมิตที่มีปัญหา” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Git Advanced: Monorepo, Submodules & Workflows ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Git Advanced: Monorepo, Submodules & Workflows มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “Bisect: ตามหาคอมมิตที่มีปัญหา”
ใช้ git bisect ค้นหาแบบทวิภาคผ่านประวัติ เพื่อระบุคอมมิตที่ทำให้เกิดบั๊กได้อย่างแม่นยำ แม้ต้องตรวจสอบคอมมิตหลายร้อยรายการ คุณปฏิบัติ Git Advanced: Monorepo, Submodules & Workflows ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Git Advanced: Monorepo, Submodules & Workflows หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Git Advanced: Monorepo, Submodules & Workflows บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “Bisect: ตามหาคอมมิตที่มีปัญหา” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Git Advanced: Monorepo, Submodules & Workflows นี้ได้ไหม
ได้ บทเรียน Git Advanced: Monorepo, Submodules & Workflows ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การรีเบสแบบโต้ตอบและการแก้ไขคอมมิต
- การเก็บและเลือกนำการเปลี่ยนแปลงมาใช้
- Reflog สำหรับการกู้คืน
- Bisect: ตามหาคอมมิตที่มีปัญหา