What is git bisect, and when would you use it?
git bisect does a binary search through commit history to find the exact commit that introduced a bug. You mark one good and one bad commit, and Git checks out midpoints until it finds the first bad one.
Explain it simply
A bug appeared somewhere in the last 200 commits and nobody knows where. Checking each would take forever. Bisect plays the number-guessing game: 'I am thinking of a number from 1 to 200'; each answer halves the options.
You tell Git a commit where it worked and one where it is broken. Git checks out the middle one; you test and answer good or bad; it halves again. About eight steps cover 200 commits, since 2 to the power 8 is 256. At the end Git names the first bad commit. Finish with git bisect reset.
Example
git bisect start
git bisect bad # current version is broken
git bisect good v1.4.0 # this tag worked
# Git checks out a middle commit; test it, then:
git bisect good # or: git bisect bad
git bisect resetWhat to say in the interview
"git bisect binary-searches history for the commit that introduced a bug. I mark a good and a bad commit, then answer good or bad for each commit Git checks out. It takes about log2(n) steps, and git bisect reset takes me back."