Skip to content

Instantly share code, notes, and snippets.

@jonchurch
Last active August 19, 2022 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonchurch/2cf23b2fcb6de455436b202455188d27 to your computer and use it in GitHub Desktop.
Save jonchurch/2cf23b2fcb6de455436b202455188d27 to your computer and use it in GitHub Desktop.
Ignoring Formatting Commits in Git Blame with Ignore Revs

Ignoring Formatting Commits in Git Blame

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:

  1. the CLI flag --ignore-rev <commit>
  2. the CLI flag --ignore-revs-file <file> which accepts a file in fsck.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!
  3. 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)

Use with GitLens VSCode Extension

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment