Bird
Raised Fist0
Gitdevops~10 mins

Bisect for finding bug-introducing commits in Git - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Bisect for finding bug-introducing commits
Start Bisect
↓
Mark Good Commit
↓
Mark Bad Commit
↓
Git Chooses Mid Commit
↓
Test Mid Commit
↓
Good
↓
Mark Good
↓
Repeat Until One Commit Left
↓
Found Bug-Introducing Commit
↓
End Bisect
The bisect process narrows down the commit range by marking commits as good or bad, testing the middle commit each time, until it finds the exact commit that introduced the bug.
Execution Sample
Git
git bisect start
git bisect good v1.0
git bisect bad v2.0
# test commit chosen by git
# mark good or bad
# repeat until found
This sequence starts bisect, marks known good and bad commits, then tests commits in between to find the bug-introducing commit.
Process Table
StepActionCommit TestedResultNext Step
1Start bisect-Bisect startedMark good commit
2Mark good commitv1.0Marked as goodMark bad commit
3Mark bad commitv2.0Marked as badGit picks middle commit
4Test middle commitv1.5Bug presentMark bad commit
5Mark bad commitv1.5Marked as badGit picks new middle commit
6Test middle commitv1.25Bug absentMark good commit
7Mark good commitv1.25Marked as goodGit picks new middle commit
8Test middle commitv1.375Bug presentMark bad commit
9Mark bad commitv1.375Marked as badGit picks new middle commit
10Test middle commitv1.3125Bug absentMark good commit
11Mark good commitv1.3125Marked as goodGit picks new middle commit
12Test middle commitv1.34375Bug presentMark bad commit
13Mark bad commitv1.34375Marked as badOne commit left
14Bisect completev1.34375Bug introduced hereEnd bisect
💡 Bisect ends when only one commit remains between good and bad, identifying the bug-introducing commit.
Status Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6After 7Final
Good Commit-v1.0v1.0v1.25v1.25v1.3125v1.3125v1.34375v1.34375
Bad Commit-v2.0v1.5v1.5v1.375v1.375v1.34375v1.34375v1.34375
Current Tested Commit-v1.5v1.25v1.375v1.3125v1.34375---
Bisect StateNot startedStartedIn progressIn progressIn progressIn progressIn progressCompleteComplete
Key Moments - 3 Insights
Why does git pick the middle commit between good and bad commits?
Git uses a binary search approach to quickly narrow down the commit range by testing the middle commit, as shown in steps 4, 6, 8, 10, 12 in the execution_table.
What happens if the tested commit is good?
If the tested commit is good, it becomes the new 'good' commit, narrowing the search range, as seen in steps 6, 10, and 11.
When does bisect end?
Bisect ends when only one commit remains between the good and bad commits, identifying the bug-introducing commit, as in step 14.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4. What was the result of testing commit v1.5?
ABug present
BBug absent
CCommit marked good
DBisect ended
💡 Hint
Check the 'Result' column for step 4 in the execution_table.
At which step does the bisect process mark commit v1.25 as good?
AStep 5
BStep 6
CStep 7
DStep 8
💡 Hint
Look for 'Mark good commit' action with commit v1.25 in the execution_table.
If the commit tested at step 8 was good instead of bad, how would the next tested commit change?
AGit would pick a commit between v1.25 and v1.375
BGit would pick a commit between v1.375 and v1.5
CGit would pick a commit between v1.0 and v1.25
DBisect would end immediately
💡 Hint
Refer to the binary search logic in the concept_flow and variable_tracker.
Concept Snapshot
git bisect start
Mark a known good commit: git bisect good <commit>
Mark a known bad commit: git bisect bad <commit>
Git tests middle commits between good and bad
Mark tested commits as good or bad
Repeat until one commit remains
This commit introduced the bug
Full Transcript
Git bisect helps find the commit that introduced a bug by using a binary search. You start bisect, mark a known good commit where the bug was absent, and a known bad commit where the bug is present. Git then picks the middle commit to test. If the bug is present, mark it bad; if absent, mark it good. This narrows the search range. Repeat testing and marking commits until only one commit remains between good and bad. This commit is the one that introduced the bug. The process is efficient because it halves the search space each time.

Practice

(1/5)
1. What is the main purpose of git bisect?
easy
A. To delete old commits from history
B. To merge two branches automatically
C. To create a new branch from the current commit
D. To find the first commit that introduced a bug

Solution

  1. Step 1: Understand the role of git bisect

    Git bisect helps identify which commit introduced a bug by testing commits between a known good and a bad commit.
  2. Step 2: Compare with other git commands

    Merging branches, deleting commits, or creating branches are different git operations unrelated to bisect.
  3. Final Answer:

    To find the first commit that introduced a bug -> Option D
  4. Quick Check:

    git bisect = find bug commit [OK]
Hint: Bisect narrows down bug commit by testing between good and bad [OK]
Common Mistakes:
  • Confusing bisect with merge or branch commands
  • Thinking bisect deletes commits
  • Assuming bisect creates branches
2. Which command correctly starts a bisect session assuming HEAD is bad and v1.0 is good?
easy
A. git bisect start v1.0 HEAD
B. git bisect start HEAD v1.0
C. git bisect begin HEAD v1.0
D. git bisect init v1.0 HEAD

Solution

  1. Step 1: Recall git bisect start syntax

    The correct syntax is git bisect start <bad> <good>, where the first argument is the bad commit and the second is the good commit.
  2. Step 2: Match the given commits

    Since HEAD is bad and v1.0 is good, the command is git bisect start HEAD v1.0.
  3. Final Answer:

    git bisect start HEAD v1.0 -> Option B
  4. Quick Check:

    git bisect start bad good = start [OK]
Hint: Start bisect with bad commit first, then good commit [OK]
Common Mistakes:
  • Reversing good and bad commits in the command
  • Using incorrect command like bisect begin or init
  • Omitting the start keyword
3. Given this bisect session output:
Bisecting: 3 revisions left to test after this (roughly 2 steps)
Testing commit abc1234

If you run git bisect good and then git bisect bad on the next commit, what will git do next?
medium
A. Git will narrow down the range and checkout the next commit to test
B. Git will end the bisect session immediately
C. Git will reset to the original branch without changes
D. Git will throw an error because you cannot mark good then bad consecutively

Solution

  1. Step 1: Understand bisect workflow

    Marking commits as good or bad tells git which side of the commit range to keep searching. After marking, git checks out the next commit to test.
  2. Step 2: Analyze the given commands

    Marking one commit good, then the next bad, narrows the search range. Git continues bisecting until it finds the first bad commit.
  3. Final Answer:

    Git will narrow down the range and checkout the next commit to test -> Option A
  4. Quick Check:

    Mark good/bad -> git picks next commit [OK]
Hint: Mark commits good/bad to let git pick next test commit [OK]
Common Mistakes:
  • Thinking bisect ends after one good and one bad mark
  • Assuming git resets automatically after marking
  • Believing marking good then bad consecutively causes error
4. You started a bisect session but accidentally marked a good commit as bad. What is the best way to fix this?
medium
A. Edit the .git/BISECT_LOG file manually to fix the mistake
B. Run git bisect skip on the wrong commit
C. Run git bisect good on the same commit to correct it
D. Run git bisect reset and start over

Solution

  1. Step 1: Understand bisect marking correction

    Git bisect allows re-marking a commit to correct its status if marked incorrectly.
  2. Step 2: Correct the marking

    Run git bisect good on the commit you accidentally marked as bad to update the bisect state.
  3. Final Answer:

    Run git bisect good on the same commit to correct it -> Option C
  4. Quick Check:

    Re-mark good/bad to correct [OK]
Hint: Re-mark the commit with git bisect good to fix [OK]
Common Mistakes:
  • Thinking you must reset instead of re-marking
  • Editing internal git files manually
  • Using skip to fix a marking error
5. You have a large project with 1000 commits. You know commit abc123 is good and def456 is bad. You want to find the first bad commit using git bisect. Which sequence of commands correctly performs this task?
hard
A. git bisect start def456 abc123; git bisect bad def456; git bisect good abc123; test commits; git bisect reset
B. git bisect start abc123 def456; git bisect bad abc123; git bisect good def456; test commits; git bisect reset
C. git bisect start def456 abc123; git bisect good def456; git bisect bad abc123; test commits; git bisect reset
D. git bisect start abc123 def456; git bisect good def456; git bisect bad abc123; test commits; git bisect reset

Solution

  1. Step 1: Start bisect with bad then good commit

    The correct syntax is git bisect start <bad> <good>. Since def456 is bad and abc123 is good, the command is git bisect start def456 abc123.
  2. Step 2: Mark the known commits correctly

    Mark the bad commit with git bisect bad def456 and the good commit with git bisect good abc123. Then test intermediate commits as git suggests.
  3. Step 3: Finish bisect session

    After finding the first bad commit, run git bisect reset to return to the original branch.
  4. Final Answer:

    git bisect start def456 abc123; git bisect bad def456; git bisect good abc123; test commits; git bisect reset -> Option A
  5. Quick Check:

    Start with bad then good, mark correctly, reset [OK]
Hint: Start bisect with bad then good commit, mark accordingly [OK]
Common Mistakes:
  • Reversing good and bad commits in start command
  • Marking commits with wrong status
  • Skipping reset after bisect finishes
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard