Sunday, January 27, 2013

git bisect

The bisect command does a binary search through the commit history in order to help you identify which commit introduced an issue.
To begin a git bisect, the first command is:
git bisect start
After this, you must tell git a bad and a good commit:
git bisect bad # or git bisect bad HEAD
git bisect good HEAD~10
In this example, the HEAD is broken and that 10 commits before the HEAD is a good point.
Git will then begin the binary search and ask you about the state (good/bad) of the current revision.
You tell this by running:
git bisect good
or
git bisect bad
At the end, git will tell you the commit that introduced the issue.
In order to stop the git bisect you must run:
git bisect reset
You should run this command after finishing the search.

Finally, if you have a script that returns 0 if a commit is good and a non-zero result otherwise, you can find out the bad commit in 2 lines:
git bisect HEAD last_good_revision
git bisect run ./script.sh

References:
http://git-scm.com/book/en/Git-Tools-Debugging-with-Git

No comments:

Post a Comment