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 commit that most recently 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/PacktPublishing/Git-Version-Control-Cookbook-Second-Edition_tips_and_tricks.git $ cd Git-Version-Control-Cookbook-Second-Edition_tips_and_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 line in the file with the commit ID and author, we'll run git blame
on the file. We can further limit the search to specific lines with the -L <from>...