Git bisect – squash your regression bugs quicker

Git bisect – squash your regression bugs quicker

Git & Git bisect

If you are a software developer or studying computer science or another IT subject, you probably have heard and used git. It is great and powerful version control software.

Great! But have you also used git bisect ?

Imagine you have a big git repository and there is a bug in the latest version of your software. Even worse, its a regression. Meaning you know that thing used to work in the past, but now its broken. Who introduced this bug? When? What broke the function?

You could test every single commit between the good one and the broken. But what if there are hundreds or thousands?

It would be much more efficient to jump exactly in the middle of the history between the broken and good commit, test that, then jump in the middle between the youngest good and the oldest bad commit and, so on.

For example:

  • on the right side are the newer commits on the left the older ones
  • arrows indicate which commit to test
  • red-diamond are the commits you have tested and found to be broken
  • blue-squares are the commits you have tested and found to be good


git bisect principle

(BTW. I’m using shapes and colours to help colour-blind people like me, there are more of us than you think. Please make our lives easier https://en.wikipedia.org/wiki/Color_blindness)

Guess what, that is exactly what `git bisect` is doing for you!

Checkout the point of your repo that has the bug, then start the bisecting with

git bisect start

Tell git that this is a bad commit:

git bisect bad

Then tell git any commit that you know did not have the bug:

git bisect good <git reference>

The git reference can be a tag-name, a commit id or any other valid reference.

Git bisect will checkout the next commit to test, test it and if its the one that does not have the bug tell git so:

git bisect good

If it is already broken do:

git bisect bad

Git will take you to the next commit to test, tell it again if its good or bad, and so on till you get a message like:

f53a8b766190143ea80658170730791ada4db56b is the first bad commit

You’ve made it! This is the commit that introduced the bug!

Simple hey! Only thing left to do is `git bisect reset` to get you back to the point you have started at, fix the bug, and of course add tests so that the regression is not gonna happen again!

Binary bisect

So that is all fine, but what if you have to compile your software every time you want to test it and its a huge code base? Maybe it takes you an hour or two to compile every time you want to test a commit. Even with bisect it will take you ages to find the right commit.

Ask @LibreOffice developers, they have that problem, but they also found a solution: do the compilation work in advance.

  1. compile every commit of your software
  2. save the compiled version in a separate git repo
  3. use `git bisect` to jump between the compiled commits and find the commit that introduced a bug

You might think: “it will be a huge repo”. True, but not as huge as you might think, there is still the advantage of de-duplication in git

“It will take a exponential time to compile every commit” - Use CI! Automate the stuff!

Read more about what and how @LibreOffice is doing and try it by bibisecting a bug in #LibreOffice: https://wiki.documentfoundation.org/QA/Bibisect

And watch Matthew Francis's talk about bisect and bibisect https://www.youtube.com/watch?v=WLmEfvjVN7s

Happy coding ??????????????

要查看或添加评论,请登录

Artur Neumann的更多文章

  • Automated Black-Box Tests for System Settings of a Micro-service Application

    Automated Black-Box Tests for System Settings of a Micro-service Application

    oCIS is the new generation open source file-sync and sharing platform, built by ownCloud, who also created the ownCloud…

  • Behaviour Driven Development on Software Rewrite

    Behaviour Driven Development on Software Rewrite

    Imagine you have an application, it works great, but you need to rewrite it, maybe because the architecture is hitting…

  • Contributing to up-stream projects

    Contributing to up-stream projects

    Behat is a BDD framework for PHP and it has a Cucumber parser called Gherkin. It’s a great tool but it missed a feature…

    1 条评论
  • Are you safe enough to take risks?

    Are you safe enough to take risks?

    Company values are great, but if they are only saved away in a document they are useless. The values need to be saved…

  • Demonstrating TDD (Test-driven development) in Go

    Demonstrating TDD (Test-driven development) in Go

    TDD is the practice to write tests before code and it should reduce failure rates and defects in your software. In this…

  • Demonstrating BDD (Behavior-driven development) in Go

    Demonstrating BDD (Behavior-driven development) in Go

    In "Demonstrating TDD (Test-driven development) in Go" I've written about TDD and this time I want to demonstrate BDD…

    1 条评论
  • Organize your company the geek-way

    Organize your company the geek-way

    How do you organize your documents in your department / company / startup ? Your policies, your minutes of meetings…

    2 条评论
  • Should you write acceptance tests for bugs?

    Should you write acceptance tests for bugs?

    As a developer or as a QA-engineer you found a bug in a piece of code, and you cannot fix it straight away (maybe its…

  • first 24h programming with Go

    first 24h programming with Go

    Because I had yesterday a long overlay at the airport in KL, I decided to use the time to learn a bit of programming…

  • No experience, no job!

    No experience, no job!

    In job applications the applicants are often asked about their work-experience. But how do you gain work-experience in…

社区洞察

其他会员也浏览了