This repository is a simple demo of the git bisect command, which helps identify the specific commit that introduced a bug or issue by performing a binary search across the commit history. Find a very basic calculate.py which contains several functions and some bugs introduced (on purpose).
- Learn how to use git bisect: This demo demonstrates how to find the commit that introduced a bug using git bisect.
- Practice using git bisect commands: We'll cover marking commits as "good" or "bad" and interpreting the output.
git clone https://github.com/YOUR_USERNAME/git-bisect-demo.git
cd git-bisect-demo
Use git log to review the commit history and identify:
- A "good" commit: one before the bug was introduced.
- A "bad" commit: one where the bug is confirmed to exist.
Begin the bisect session by marking the known good and bad commits:
git bisect start
git bisect bad <bad_commit_hash>
or use
git bisect bad HEAD #last commit
git bisect good <good_commit_hash>
git bisect will now automatically check out commits between the "good" and "bad" points. Test each checked-out commit for the bug. Based on the results, mark each commit:
git bisect good # if the bug is absent
git bisect bad # if the bug is present
Once git bisect has identified the exact commit that introduced the bug, reset the bisect session: (very important)
git bisect reset