Eric Guo's blog.cloud-mes.com

Hoping writing JS, Ruby & Rails and Go article, but fallback to DevOps note

Using Git blame.ignoreRevsFile Options to Ignore Your Auto Format Coding Commits

Permalink

After running any auto-format on a repository, git blame becomes almost useless because every line is “last touched” by the formatting commit.

Git has a built-in solution: tell git blame to ignore specific commits.

Create .git-blame-ignore-revs in root repo.

.git-blame-ignore-revs
# Formatting / reindent / whitespace-only commits
1a2b3c4d
abcdef01

Enable it in your repo via git

git config --local blame.ignoreRevsFile .git-blame-ignore-revs

Now when you run git blame, those commits will be skipped and you can see the real history again.

Notes

  • Commit .git-blame-ignore-revs into your repo so GitHub (and other developers) can use the same ignore list.
  • GitHub also reads .git-blame-ignore-revs automatically in the web UI, so you’ll get the same “clean blame” there too.

Comments