Git Bisect
git bisect finds the commit that broke something. You mark one commit as good and one as bad, and Git checks out the commit halfway between them for you to test.
Each answer halves the number of commits left, so even hundreds of commits take only a few steps. git bisect reset takes you back to where you started.
Find when the price became 0
git bisect start
status: waiting for both good and bad commits
git bisect bad
status: waiting for good commit(s), bad commit known
git bisect good HEAD~7
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[314bfbf8181c57edfe4848d8a40a2faec01f0f62] Version 4
cat price.txt
price = 10
version = 4
git bisect good
Bisecting: 1 revision left to test after this (roughly 1 step)
[1ff5d2c0c7ca2cca09274f25f0c603c2c4558019] Version 6
cat price.txt
price = 0
version = 6
git bisect bad
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[192d3d29478a7044379ec037eca437f26018ceb5] Version 5
cat price.txt
price = 10
version = 5
git bisect good
1ff5d2c0c7ca2cca09274f25f0c603c2c4558019 is the first bad commit
commit 1ff5d2c0c7ca2cca09274f25f0c603c2c4558019
Author: W3Schools Test <test@example.com>
Date: Thu Nov 5 10:58:57 2026 +0100
Version 6
price.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
git bisect reset
Previous HEAD position was 192d3d2 Version 5
Switched to branch 'main'
Let a command do the testing
With git bisect run, Git runs a command on each commit. Exit code 0 means good, anything else means bad:
git bisect start HEAD HEAD~7
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[314bfbf8181c57edfe4848d8a40a2faec01f0f62] Version 4
git bisect run grep -q "price = 10" price.txt
running 'grep' '-q' 'price = 10' 'price.txt'
Bisecting: 1 revision left to test after this (roughly 1 step)
[1ff5d2c0c7ca2cca09274f25f0c603c2c4558019] Version 6
running 'grep' '-q' 'price = 10' 'price.txt'
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[192d3d29478a7044379ec037eca437f26018ceb5] Version 5
running 'grep' '-q' 'price = 10' 'price.txt'
1ff5d2c0c7ca2cca09274f25f0c603c2c4558019 is the first bad commit
...
bisect found first bad commit