Published at
Updated at
Reading time
This post is part of my Today I learned series in which I share all my web development learnings.

After ten years of being a vivid space user, I decided to move all my projects to tabs. ๐Ÿ˜ฒ

I applied this change to this blog's repository, and a problem came to light. If you change the formatting of hundreds of files, you're messing with your Git history. git blame becomes pretty useless. Thousands of lines will be marked with an unimportant formatting change.

VS Code blame showing many "move to tabs" commits

I started googling around to find out how to ignore commits in Git and VS code...

Ignore commits via --ignore-rev

If you use git blame on the command line, the --ignore-rev option lets you blame a file without considering this nasty formatting commit.

git blame --ignore-rev a926bba49c index.js

This is great but didn't help me because I rarely use git blame on the command line, and even if I would, I wouldn't want to always think of this argument.

I just want git blame to work.

Ignore commits via --ignore-revs-file

I continued the CLI journey. You can also define a file to specify all commits that should be ignored by git blame with the --ignore-revs-file argument.

I created a .git-blame-ignore-revs file (more on this file name later!)...

# Changed everything to tabs

... and referenced the file when using git blame:

git blame --ignore-revs-file .git-blame-ignore-revs index.js

This approach works better because now I could add future commits to the revision file, and whenever the useless commits stand in the way, I could use the --ignore-revs-file flag.

But it's not ideal and it still didn't work in VS Code.

Add ignored revisions to your local Git config

To make things work in VS Code, I added the blame.ignoreRevsFile option to my local git config.

git config blame.ignoreRevsFile .git-blame-ignore-revs

This command added a new entry to your local .git/config file.

    ignoreRevsFile = .git-blame-ignore-revs

On the command line, git blame then ignores the specified commits automatically.

git blame index.js

And after restarting VS Code, it picked up the new Git config and didn't show the formatting commit anymore! ๐ŸŽ‰

Git blame in VS Code ignoring the formatting commit.

Unfortunately, the described Git config option is only a local one. It won't make it to another machine. That's why I adjusted the git-blame-ignore-revs file with a small note.

# Run this command to always ignore formatting commits in `git blame`
# git config blame.ignoreRevsFile .git-blame-ignore-revs

# Changed everything to tabs

There's probably some tooling to streamline this process; if you have ideas, please let me know!

Fun fact: GitHub picks up .git-blame-ignore-revs

And to close things: here's a little fun fact. If the file holding your ignored commits is named .git-blame-ignore-revs, GitHub picks it up automatically.

GitHub blame interface telling that it's ignoring revisions due to a .git-blame-ignore-revs file.

And that's it! If you have tips or ideas on how to deal with useless commits, send them my way!

Was this TIL post helpful?
Yes? Cool! You might want to check out Web Weekly for more quick learnings. The last edition went out 4 days ago.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles