Posts git bisect - [Git Good]
Post
Cancel

git bisect - [Git Good]

Here we go again, another broken feature in your software. But it was working yesterday! Or was it two days ago? In this case, you’d better use a little known Git feature, that is git bisect, to find the malicious commit. In short, it is a handy interface to perform binary search over the history of changes.


Usage

Suppose that the current commit commit-B is known to be broken, while the commit-A used to work fine.

1
2
3
git bisect start            # Start from this commit ...
git bisect bad              # ... which is broken ...
git bisect good commit-A    # ... whereas commit-A was ok

At this point, bisect will automatically checkout to some intermediate commit between commit-A and commit-B. Test again the feature. Does it work?
If yes, do git bisect good, otherwise say git bisect bad.
Depending on your feedback, bisect will switch again to another intermediate commit, and so on until you catch the nasty bug. When you’re done, simply do git bisect reset to move back to HEAD.


Tip

Commit frequently to take advantage of this tool and save a lot of time.
Debugging with bisect takes O(log(n)) time w.r.t. lines of code, visual inspection is O(n) instead.

This post is licensed under CC BY 4.0 by the author.

Trending Tags

Contents

Trending Tags