Git blame flooded by formatting commits—don't rewrite history yet
Formatting commits make blame attribute everything to the same person. First use git show to confirm only formatting changed, then use ignore-revs-file to make queries skip it. Change the query, not history; if logic changes are mixed in, don't skip it.
Git blame is used to find which commit last changed each line. Once a formatting commit lands, dozens or hundreds of lines are all attributed to the same commit, hiding the original authors. Someone shared a method: first confirm the commit only changes formatting, then make blame queries skip it.
First inspect the commit:
git show <commit>
Only continue if the diff contains just changes like whitespace, indentation, line breaks, or quote style. If logic changes are mixed in, do not skip it; otherwise the attribution will miss real changes.
Write the full commit hashes into ignore.txt, one per line:
<full-commit-hash-1>
<full-commit-hash-2>
Use full hashes, not abbreviations. The file format is the same as fsck.skipList; blank lines and comments starting with # are ignored.
When checking attribution, include the ignore file:
git blame --ignore-revs-file ignore.txt -- path/to/file
Put the file name after -- to avoid confusing the file name with a revision. This option only adjusts blame queries; it does not delete commits or change repository history.
Teams with many formatting commits can configure:
git config blame.ignoreRevsFile ignore.txt
This saves writing the option by hand every time. The prerequisite is still confirming that the commits contain no logic changes.
Git documentation states that --ignore-rev and --ignore-revs-file ignore a revision when assigning attribution, as if that change never happened. Lines changed by ignored commits that cannot be attributed to another commit can be marked via blame.markUnblamableLines. Turn it on when you need to investigate.
Source: git-blame documentation
发布时间: 2026-11-30 01:05