Git protip: blame, please don’t!
By Maxime Bréhin • Published on 10 October 2022 • 1 min

For goodness’ sake 🙏, tell me you don’t use git blame! Apart from its implied intent, that command will not display the information you’re looking for, but worse, you’re probably going to misinterpret it and go heckle an innocent colleague (adding insult to injury 😡).

What does this command do? It shows what revision and author last modified each line of a file but without displaying what changed!

This means that your colleague may have removed whitespaces or reindented the lines you were analyzing, so they ’re not the author of the bug you found. And you’ll look like an idiot when it turns out it was you who failed and actually introduced the bug.

This brings us to the correct approach: tracking changes to the line range with git log -L. There are other options like -S or -G you may be interested in. You can learn more about it in that other article.

Would you like to go one step further and fully master Git core concepts, or to get advice on how to guarantee the quality of your Git projects? We can help or train you - just tell us what you need!