brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tell git blame to ignore a big reformatting commit

Git
~/tips/tip-git-blame-ignore-revs

0123456789abcdef0123456789abcdef01234567

Makes git blame skip commits like mass reformatting so it shows who really wrote a line.

One commit that reformats every file, and suddenly git blame says that person wrote all of it. That is useless, and it is fixable.

Git can skip chosen commits when it assigns blame. Put the full hashes of those commits in a file, one per line. Comments starting with # are allowed. The common name is .git-blame-ignore-revs.

# prettier run
0123456789abcdef0123456789abcdef01234567

Then tell git to use it:

git config blame.ignoreRevsFile .git-blame-ignore-revs
git blame --ignore-revs-file .git-blame-ignore-revs app.js

The config setting makes it permanent for the repo. The option does it for one run. According to the docs, lines changed by an ignored commit are blamed on the previous commit that touched that line or nearby lines.

If you set blame.markIgnoredLines, those lines get a ? in the output, so you know the answer is a guess.

The caveat is in that last part. The earlier commit it points to may be a rough match, not the real author of the line. Also, the file needs unabbreviated hashes, so copy them in full. The config is a local setting, so each person who clones the repo has to set it once.

Further reading: git blame documentation, On this site: turn on rerere and resolve the same conflict only once, On this site: git commit –fixup plus –autosquash keeps your history clean without any editing, On this site: Guide: let git bisect find the commit that broke your code

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link