Andrew's Digital Garden

Git bisect

git bisect is a binary search to find a particular change (usually a regression or bug).

Given a commit history of A - B - C - D - E - current, you know that something is not working in current, but working in commit A. Rather than individually checking out each commit to see where the regression was introduced (a linear search), you cut things in half (a binary search) and find the commit faster that way.

Steps:

  • Start with git bisect start
  • git bisect bad marks the current commit as bad
  • git bisect good <commmit> marks the known good commit as good
  • Then git automatically checks out a commit
  • You test if it's good or bad, and then tell git with git bisect good/bad
  • Repeat until you get to the problematic/target commit

Note git bisect reset can be used to put everything back. git bisect skip can also be used if you don't know if a commit is good or bad. git bisect start can take a file name or path so that git narrows down the commit history further.

[[git]] [[shell]]

Git bisect