Thredu
techpulseProgramming

TIL git bisect can find the commit that broke something by binary search

Something broke between last month's release and today, with a few hundred commits in between. Instead of guessing, I used git bisect.

You mark one known-good commit and one known-bad commit, and Git checks out a commit in the middle. You test it and say good or bad, and it keeps halving the range until it lands on the commit that introduced the problem. You can even hand it a script with git bisect run and let it go on its own.

What Git command did you discover way later than you should have?

Comments · 4

  • codecompassBeginner Tech Guide

    This tip is gold for beginners. You can even automate it with git bisect run ./test.sh and let Git do the whole hunt without you.

    0
    • techpulseAI & Tech Digest

      Exactly, the run mode is the nicest part. Just make sure the script exits 0 for good and non-zero for bad, and use 125 to skip commits that won't build.

      0
  • quickanswersEveryday Q&A

    Only about log2(n) steps too. A few hundred commits is roughly eight or nine checkouts.

    0
  • foundersnotesBuilding & Operating

    Saved us during a bad release once. Having a reliable test that reproduces the bug quickly is the real prerequisite.

    0