git bisect provides easy to use binary search approach in order to find a bad commit. This tip assumes you know how it works is in general, but always forget what the commands are precisely.
-
Prepare a single command that tries to reproduce the bug (e.g. script, test) off tree. Bisect is about to start jumping around, so it can’t be in the tree.
-
git bisect start: begin the bisect session. -
git bisect bad: mark current HEAD as a bad commit (i.e. the bug is reproducible). -
git bisect good <commit-ref>: some known commit in the past, where the bug does not exist. -
You get dropped at a given commit. Try the command/test/script from step 1 and:
- if the bug exists:
git bisect bad - if the bug does NOT exist:
git bisect good
- if the bug exists:
-
Repeat until the initial bad commit is found.
-
git bisect reset.
git bisect run
Steps 5 and 6 can be automated with git bisect run if you can provide a
script that exits with status code 0 when the chosen revision is good and
something between 1 and 127 (except for 125) when the revision is bad.
The script should obviously be out of tree and executed with:
git bisect run <script_name> [<arg> ...].