1001Ferramentas
🔍 Dev

.git-blame-ignore-revs Generator

List of commit hashes for Git to ignore in blame (mass formatters: prettier, black, eslint --fix). Useful for large refactors.

Arquivo .git-blame-ignore-revs:

Habilite com: git config blame.ignoreRevsFile .git-blame-ignore-revs

Keeping the formatting commit out of blame

Running a formatter across the whole project solves one problem and creates another: blame starts pointing at the formatting commit instead of at whoever wrote the line. A whole file apparently authored by someone who merely ran Prettier is pure noise, and the history loses exactly the information blame exists to provide.

Git solves this with a file listing the commits to ignore. Paste the hashes, one per line, optionally followed by a description — the page assembles the file with the description becoming a comment above each hash, which is the usual convention. Save it as .git-blame-ignore-revs in the repository root.

One step is missing that almost everyone forgets: the file is not used automatically. You have to point at it in the config with git config blame.ignoreRevsFile .git-blame-ignore-revs — and every person on the team has to run that in their own copy, because configuration does not travel with the repository. It is worth putting the command in the README or the setup script. GitHub and GitLab, on the other hand, honour the file automatically when it exists.

Frequently asked questions

Do I need the full hash?
Yes, all forty characters. Git refuses an abbreviated hash in this file and fails with an error rather than ignoring it silently. Use git rev-parse HEAD or copy from log output with the full format.
What happens if a commit does not exist?
By default Git complains and blame fails. That usually happens after a rebase rewrote the listed hashes. There is a blame.markIgnoredLines setting for more tolerant handling, but the right move is keeping the file current when history is rewritten.
Can I use it for any commit I want hidden?
Technically yes, but the legitimate use is for changes that do not alter behaviour: mass formatting, quote style swaps, mechanical renames, licence header updates. Using it to hide authorship of a real change subverts the tool and confuses whoever is investigating a bug.

Related Tools