Using the blame command

The bisect command is good when you don't know where in your code there is a bug, but you can test for it and thereby find the commit that introduced it. If you already know where in the code the bug is but want to find the commit that introduced it, you can use git blame. The blame command will annotate every line in the file with the latest commit that touched that line, making it easy to find the commit ID and then the full context of the commit.

Getting ready

We'll use the same repository and branch as in the bisect example:

$ git clone https://github.com/dvaske/cookbook-tips-tricks.git
$ cd cookbook-tips-tricks
$ git checkout bug_hunting

How to do it...

We know that the bug is in map.txt on lines 37-39. To annotate each ...

Get Git: Mastering Version Control now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.