Git bisect – the awesome way to find the Mr. Bug commit

I had my first experience with git bisect the other day and it’s awesome. What happened is that I introduced a regression which was uncovered by a failing test. Yes,  yes I know I should have ran the full test suite, but I did the mistake to only run the specific set of unit test for that particular component. Now, the tricky part is that the particular test had no direct connection with the last set of commits so I had absolutely no clue which commit had caused it. Thanks to our QA team and build bot I was supplied with a range of commits which caused the regression. This is when git bisect came into play.

Supplied a range of commits git bisect automatically

1. Given a supplied range of commits starts chopping sets of them and applying in a binary search fashion until you mark the current commit as good. Say if you have 50 commits to bisect it will apply the first 25 if you mark the 25th commit as good then the regression is in those 25 commits so it will apply the first 12 of those and then if you mark them as bad it will apply the next 13 and it will then keep subsetting until you hit the bad commit. Nice and quick.

2. Create a temporary bisect branch where it operates (which when done is automatically removed as well)

The workflow is as follows:

git bisect start

# Mark current commit as bad
git bisect bad

# Set the first good commit - the start of the bisect commit set
git bisect good some-commit-here

.. compile and run tests ...

# Mark the current commit as either bad or good
# Git will automatically apply the next subset of commits if bad
git bisect good / bad

# Done bisecting - we found the bad commit
git bisect reset

There are lots of other cool things that you can do like visualize the bisect set, skip range of commits in side the set or even log your actions to a file so that if you make a mistake somewhere you can just reply the actions from the log file. Ah and last but not least you can also use git reset to manually move up the bisect commits set. For more info check out the manual.

Be Sociable, Share!
  • Lw

    “git bisect run” is even more awesome. It executes a test script and bisect will use script's return value to decided whether the revision is good or bad. In other words, you can leave your computer to do the bisecting automatically.

  • Lw

    “git bisect run” is even more awesome. It executes a test script and bisect will use script's return value to decided whether the revision is good or bad. In other words, you can leave your computer to do the bisecting automatically.

  • http://www.bootoutlet.co.uk/ ugg boots

    Hhe article's content rich variety which make us move for our mood after reading this article. surprise, here you will find what you want! Recently, I found some wedsites which commodity is colorful of fashion. Such as that worth you to see. Believe me these websites wont let you down. ed hardy clothes

  • http://www.kalendarze.dogory.pl PeepibreWaype

    Our company creates a matter card on the underpinning of unexcelled and magnificent projects.
    These projects are carried revealed by way of the cards the most outstanding pike of unmistakable artists and designers in
    the shop who are experts in every intelligibility of the word. They are also extraordinarily supple, so you can
    complete very compelling trade easter card designs, depending on the solitary needs of each client.
    We do not own a masterful printing machines guarantee the highest distinction of each individualistic card.
    Deviating batch of identification b docket allows you to meet the expectations of notwithstanding the most urgent customers
    from every conceivable industry. We guarantee the language and advantage of huge quantities of vocation
    cards in the shortest doable time. In our case, the highest grandeur is the payment of the proposed
    value and trusty service from people receiving and carrying out an pecking order recompense business cards.
    With access to the services offered including our website, you can quickly and without undue
    formalities stick an degree with a view goods, review the commitment and approved it and ordered some task
    cards. Settle upon our company as a good organization postcard is often a obligation after success.
    Greet
    Merio Kalendarze

  • http://twitter.com/OpenSimFan André Verwijs

    when i run git bisect on (debian) linux, i’m not getting any information back.
    something like: “Bisecting: xxx revisions left to test after this…” so i don’t know what happens…
    can i turn this on?