A bug appeared sometime in the last 200 commits. How do you find the culprit fast?
IntermediateScenarioBranching and Merging Workflows
Answer
Situation read → Binary search over history needs a known good commit and a reliable test.
What I'd do →
- Start:
git bisect start,git bisect bad HEAD,git bisect good v2.1.0. - Automate with a script that exits 0 for good and non-zero for bad:
git bisect run ./scripts/repro.sh
git bisect reset
- Read the reported first bad commit and inspect it with
git show.
Why → 200 commits need about 8 steps. Exit code 125 in the script tells bisect to skip an untestable commit.
Interview tip → Linear history (squash or rebase) makes bisect cleaner, since merge commits can confuse results.
More on Branching and Merging Workflows
You run `git pull` and Git stops with a merge conflict in `app.py`. What do you do?BeginnerYour feature branch is three weeks old and `main` has moved a lot. Merge `main` in, or rebase onto it?IntermediateThe team argues about fast-forward merges versus merge commits on `main`. How do you settle it?BeginnerA teammate branched from the wrong base, and their PR shows 40 unrelated commits. How do you fix it?IntermediateBefore merging, you want to see exactly what the feature branch adds compared to `main`. Which commands?BeginnerHalfway through a merge you realise you pulled the wrong branch. How do you back out?Beginner