Keep git blame useful after a mass reformatting commit
Short answer: After a big reformatting commit, such as switching formatters, changing indentation or renaming across the codebase, git blame points nearly every line at that one commit, and the real history disappears from view. Put the commit's full hash in a .git-blame-ignore-revs file at the repository root, and tell Git to use it with git config blame.ignoreRevsFile .git-blame-ignore-revs. Blame then skips the commit and shows who really wrote each line. GitHub's blame view reads the same file automatically.
Why blame matters to a small team
git blame shows, for each line of a file, the last commit that changed it. Teams use it constantly, often without calling it that: "who added this discount rule?", "why does this check exist?", "when did this start?". From the commit, you reach the pull request, the discussion and often the original reason.
That chain breaks after a mass change. Reformatting the codebase with a new tool, converting tabs to spaces, renaming a widely used function or reorganising imports touches thousands of lines in one commit. Afterwards, blame credits every one of those lines to "Apply formatter", and the useful history sits a step further back where nobody looks.
This is the most common objection when teams consider adopting a formatter: "we'll lose blame". With an ignore file, you don't.
How ignoring revisions works
Git's blame documentation describes the --ignore-rev option as ignoring changes made by a revision when assigning blame, as if the change never happened. Lines changed or added by an ignored commit are blamed on the previous commit that changed that line or nearby lines. You can pass the option several times, or list revisions in a file with --ignore-revs-file. The blame.ignoreRevsFile setting makes Git use such a file every time, without typing the option.
The file is simple: one full commit hash per line, with optional comments starting with #. For example:
- A comment line:
# Switch to Prettier, 2026-11-09 - Then the full 40-character hash of that commit on the next line.
Setting it up
- Make the mass change in its own commit. Don't mix reformatting with real code changes; the ignore file can only skip whole commits.
- Merge it, then copy its full hash from the main branch. If your host squashes or rebases on merge, use the hash of the commit as it exists on main, not on your branch.
- Create
.git-blame-ignore-revsin the repository root, add a comment and the hash, and commit the file. - Ask everyone to run
git config blame.ignoreRevsFile .git-blame-ignore-revsonce in their clone. Put the command in the README or a setup script. - Check it works: run
git blameon a reformatted file and confirm lines show their real authors.
On GitHub and other tools
GitHub's documentation explains that revisions listed in a .git-blame-ignore-revs file in the repository's root directory are hidden from the blame view, using Git's ignore-revs-file mechanism, and describes how to bypass it when you do want to see the formatting commit. Other hosts and editors vary; many editor blame features use your local Git configuration, so the one-time config step covers them.
When to add a commit to the file
Good candidates:
- Applying a formatter to the whole codebase.
- Changing indentation, line endings or quote style everywhere.
- Mechanical renames generated by a tool.
- Moving large blocks of files without changing their content.
Don't add commits that change behaviour, even if they also reformat. Those changes need to stay visible in blame.
Limits to know
- Blame is still a best guess around ignored commits. If a reformat also split or merged lines, Git attributes them to nearby earlier changes, which is usually right but occasionally odd.
- Every clone needs the config unless your tooling sets it. A new teammate who skipped setup sees the old behaviour.
- Hashes must match the main branch. Rewriting history later, which you should avoid on shared branches, would change them.
git logisn't affected. The formatting commit still appears in history, which is correct.
Automating the setup
Relying on every developer to remember a config command is fragile. A few ways to make it automatic:
- Add the command to the script new developers already run, such as a
setuporbootstrapscript. - Run it from a dependency install hook in projects where that's acceptable to your team.
- Mention it in the pull request template for the reformatting change, so reviewers set it up the same day.
CI jobs rarely need it, unless you generate reports from blame, in which case set the same option in the job before the report runs.
Pair it with good practice
The ignore file works best alongside a formatter that runs automatically, so future commits never need another mass reformat. Mention the file in the commit message of the reformatting change, and keep a short note in your contributing guide explaining what it's for, so future developers don't delete it as clutter.
A worked example
Picture a hypothetical Cork booking-software company that delayed adopting a code formatter for a year because developers relied on blame to understand old pricing rules. When they finally reformatted the codebase in one commit, they added its hash to .git-blame-ignore-revs, committed the file, and added the config command to their setup script. In the host's blame view and in developers' editors, lines kept their original authors and pull request links, and the formatter has run on every commit since.
FAQ
Do I need the full commit hash?
Use the full hash. Short hashes can become ambiguous as the repository grows.
Can I ignore several commits?
Yes. Add one hash per line, with comments explaining each.
Will this hide the commit from history?
No. It only changes how blame assigns lines.
What if someone forgets the config step?
Their local blame shows the formatting commit as before. Nothing breaks; they just see less useful results until they set it.
If your team is planning a big cleanup and worried about losing history, tell us about your codebase and we'll help plan it.