You probably know the feeling: you're trying to figure out why something happened in a codebase, run git blame, and end up on that huge commit where you reformatted everything: every line changed, no functional impact. Finding the real author or commit message becomes a headache.

Luckily, Git provides tools to ignore specific revisions when running git blame, so your history stays helpful and focused.

Ignoring revisions through the command line

If you know the hash of the commit you want to ignore (for example decade), you can run:

git blame --ignore-rev decade app/Models/User.php

This tells Git to pretend that commit never existed for blame purposes, and instead look at who last changed the lines before that commit.

This is handy for quick checks. I usually use it to find what happened before a certain refactor, but I still want to see blame information about this refactor in other contexts, so I don't want to forever ignore this commit.

Long-term tracking of revisions to ignore

For a more permanent and shareable solution, you can list unwanted revisions in a file called .git-blame-ignore-revs at the root of your repository.

For example, create a .git-blame-ignore-revs file containing:

decade # changed from tabs to spaces
facade # changed from 5 space indentation to 3 spaces

Then you can simply run:

git blame app/Models/User.php

Git will automatically ignore those commits if it's configured to do so. This will automatically be picked up in GitHub's blame view as well.

If this does not work, you might need to configure your local git setup to use the file to ignore revisions using this file.

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

Now, all future git blame commands will respect that file.