Some commits touch many files at once to do QoL or reformat code, with trivial diffs. These commits infamously muddy the output of git blame
.
However, since git v2.23, git allows you to provide a list of commits to ignore in the blame. This feature is called "ignore revision(s)"
You can provide these commits in multiple ways:
- the CLI flag
--ignore-rev <commit>
- the CLI flag
--ignore-revs-file <file>
which accepts a file infsck.skipList
format (commits seperated by newlines, # prefixed comments allowed as of Git 2.20) NOTE: at time of writing (git v2.25.1) this flag will evaluate the path relative to your repo root, not your current working directory! - setting config option
git config blame.ignoreRevsFile .git-blame-ignore-revs
to point to a revs ignore file (set this as a local per-project config, blame will error if it cant find the file)
If you're using GitLens to show git blame info in VSCode, you can update the settings to pass custom arguments, including adding commits to ignore. I recommend using the revs file option with a file, typically named .git-blame-ignore-revs
, in your repo root.
"gitlens.advanced.blame.customArguments": ["--ignore-revs-file", "./path/from/repo/root/to/.git-blame-ignore-revs"]
Your .git-blame-ignore-revs
file could look something like this:
# Run prettier on the codebase
a9ege0b1616a97443c4d367e5e64c380507d534f
# Change import sort order rules
c869be90dfa0a7300ee3d916fa3b59af5641ee34
67674d36f55b930d0949f29e6ed8ec5a886z79f4
2f4f6a8e9e5a25b0de6c2e7445667d7b4491d50d