Debug commit with git bisect - Anjum219/Git-basics GitHub Wiki

When something was working in you repository at commit hash x and now you find out that it's not working anymore, don't panic, do bisect!

What bisect does is- it iteratively points out to a commit from the working state commit to the buggy state commit. And you test out the state of your code in each iteration.

To use bisect, start by

git bisect start

Now, tell git that the current commit is bad by

git bisect bad

Now move to the commit x that you think was working properly-

git checkout x

Test the functionality of your code at this stage and mark the commit as good by-

git bisect good

Now git will know that commit x was good, current commit is bad, so it will move to the next commit from x towards current commit

current commit (1) <- 2 <- 3 <- ... <- x

Keep testing and marking this way until you finally find the commit that caused the pain in your a**. Thank git and write-

git bisect reset

BTW, anytime you feel, bisecting is done, I wanna get out of bisect, run this reset command.