Mercurial includes an extension to look for bugs, called hbisect (adding the bisect command).


This command comes from GIT. Its behaviour is fairly simple, it takes a first revision known to be correct (i.e. without the bug) and a last revision known to be bad (i.e. with the bug). The bisect extension ouputs a revision at half between the good and the bad one and let you test it. If this revision is a good one, your mark it as such with hg bisect good, otherwise your mark it as a bad one with hg bisect bad. In both cases, bisect outputs a new revision to test, at half between the good and the bad one, until only one revision is left: the culprit.


Firstly, you need to configure your .hgrc to enable the extension by adding following lines:


Then, the bisect command should be available:

$ hg bisect help
list of subcommands for the bisect extension

 bad     mark revision as bad and update to the next revision to test
 good    mark revision as good and update to the next revision to test
 help    show help for a given bisect subcommand or all subcommands
 init    start a new bisection
 next    find and update to the next revision to test
 reset   finish a bisection


To start a bug search, you must initialize bisect:

$ hg bisect init

Usually, you have a bug in the tip, so you mark it as bad:

$ hg bisect bad

Then, you mark as good a revision known to be good:

$ hg bisect good ID-OF-KNOWN-GOOD
60 revisions left
Now testing 6df5bc5a4e5fb898fd52689dad1ffce7059aba3e

After the above command, bisect outputs a new revision to test. After each test, your mark it as good with:

$ hg bisect good
15 revisions left
Now testing 81d1c36e3205d2155fbccc49108dc55d8ba97758

or as bad with:

$ hg bisect bad
3 revisions left
Now testing f2a1d841d57eeb3cdbc078f6e0f56c83a3f86a25

Until the right one is found:

$ hg bisect bad
The first bad revision is : f2a1d841d57eeb3cdbc078f6e0f56c83a3f86a25