CodeBlanks Logo Icon CodeBlanks

Bisect

Find the buggy commit with binary search using bisect.

What Is Git Bisect?

git bisect uses binary search to find the commit that introduced a bug. First, mark a commit containing the bug as bad and an older commit without the bug as good. Git divides the commits between them so you can test each selected revision.

git bisect start
git bisect bad
git bisect good abc1234

This method helps locate faulty changes faster in long commit histories.

Practice Start a Bisect Search

Start a bisect process to find the faulty commit. First open the search, mark the current commit as bad, and mark commit abc1234 as good.

Starter code

terminal
# Bisect aramasını başlat

Sample solution

terminal
git bisect start
git bisect bad
git bisect good abc1234

Expected output

Bisect araması başlatıldı ve aralık belirlendi.

Practice Find the Faulty Commit with Binary Search

Assume that you test each commit selected by Git during the bisect process. Run git bisect bad if the test contains the bug, or git bisect good if it does not. When Git identifies the faulty commit, finish the search and return to the normal working state.

Starter code

terminal
# Test sonucu hatalıysa
# Test sonucu temizse
# Aramayı bitir

Sample solution

terminal
git bisect bad
git bisect good
git bisect reset

Expected output

Hatalı commit belirlendi ve bisect tamamlandı.

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which command marks an older commit that you know does not contain the bug?

  • git bisect good Correct answer
  • git bisect bad
  • git bisect reset
  • git bisect start

Explanation: <code>git bisect good</code> indicates that the tested commit does not contain the bug.

2 Mark the Faulty Revision

Question
git bisect start
git bisect bad
____
Answer
git bisect start
git bisect bad
bad

Explanation: <code>git bisect bad</code> indicates that the current commit contains the bug.

3 Bisect Commands

Term Meaning
git bisect start Starts the search process
git bisect good Marks a good commit
git bisect bad Marks a bad commit
git bisect reset Returns to the normal state

All lessons in Advanced