profile

ESPRESSO FRIDAYS

Git Blame Can Do More

Published 26 days ago • 1 min read

Hi Friends,

Today, we’re diving into the often under-appreciated git blame.

Often used to find out who last modified a line of code, git blame has several powerful features. Let’s explore some of these hidden gems, particularly focusing on the flags:

  • -w
  • -C
  • -C -C
  • -C -C -C

Ignoring Whitespace with the -w Flag

Do you know the annoying blame results showing over an indent or a space removed / added?
"-w" fixes that!

git blame -w file_name

And you got yourself a clean blame with the real authors of changes.

Ignoring Code Movements With -C Flag

The -C flag takes it a step further. It detects lines that were copied or moved from other files in the repository!
This is particularly useful in large projects where code refactoring and file splitting or merging are common:

git blame -C file_name

To extend the detective work, using -C -C instructs Git to examine not just the target blame file but also to look at other potential sources in the repository:

git blame -C -C file_name

The double -C makes git blame even more robust against file shifts and reorganizations, tracking down code origins through multiple levels of file history.

Maximum Traceability with -C -C -C

Finally, -C -C -C expands the search scope to its maximum:

git blame -C -C -C file_name

Triple -C helps in scenarios where significant portions of a codebase have been moved around multiple times, potentially across multiple files over an extended period. It ensures that you can trace back to the initial commits affecting the current state of any line of code.


git blame is more than just a tool for finding who wrote a line of code; it’s a gateway to the history and evolution of your project. I’ve been using it extensively recently and learned a lot about changes made over periods of time.

Since many code changes are 'obfuscated' over time because of small changes, formatters, and re-orgs, we're left with a hard-to-follow chain of events. Knowing how to remove these layers has been super helpful trying to understand code authors and why/how things were done.

Thanks for reading, have a great weekend!

Whenever you’re ready, here’s how I can help you

ESPRESSO FRIDAYS

Every once in a while I send hand picked things I've learned. Kind of like your filter to the tech internet. No spam, I promise!

Read more from ESPRESSO FRIDAYS

Focus is a huge problem in modern days. These days, lots of apps and websites try to grab our attention and keep us hooked. Most of us know we should resist these distractions. But instead of making a plan, many people just wing it. I used to do that too. But I’ve had enough. Another Instagram post, YouTube short, or funny meme won’t make me feel good about my day. In fact, they: Make my workday longer. Slow down my progress, bit by bit. So, I put together some tools and rules to help me stay...

5 days ago • 3 min read

Hi friends, On July 15th, 2019, I messed up bad. Real bad. I wanted to finish a project quickly, and show a quick POC to a customer I was working with. To make a long story short, I pushed a container, to a public repo, containing admin credentials to an AWS account. I thought of myself as a senior consultant, who delivers, fast, with no mistakes. Man I managed to break that reputation. The silver-lining however, is that I learned my lesson. So deeply so, that I’ve implemented these same...

11 days ago • 3 min read

Hi friends, Today we’re going to explore a lesser-known but incredibly powerful feature of Git: git rerere. This feature is particularly useful for anyone who frequently manages branches and encounters merge conflicts. * not a real magician What is git rerere? The git rerere feature stands for “reuse recorded resolution.” It helps to automate the resolution of merge conflicts by remembering how you’ve resolved them in the past. When enabled, git rerere kicks in as soon as a conflict occurs...

19 days ago • 2 min read
Share this post