Plain git blame points at whoever reindented or moved the code, and that is rarely the commit I am looking for. Two options skip past that.
-w ignores whitespace when comparing the parent’s version and the child’s, so a reindent no longer takes over the blame. -C detects lines that were moved or copied from other files. Given once, it looks at files modified in the same commit. Given twice, it also looks for copies from other files in the commit that creates the file, and three times looks at any commit.
git blame -w -C -C -L 40,60 src/config.py
-L 40,60 limits the output to those lines, which keeps it readable. Here is what it changes. Say a helper moved from util.py into app.py and util.py was deleted in the same commit. Plain blame:
d67fba49 ... 3) def normalize_hostname(value):
With -C, the same line is blamed on the commit that first wrote it, and the output also shows the file it came from (util.py).
Caveats: the detection has a threshold. By default -C needs at least 40 alphanumeric characters to move before it associates lines with the parent commit, so a tiny moved snippet is still blamed on the move. You can raise or lower it, for example -C20. More -C also means more searching, so on a big repository start with one and add more only when the blame still lands on a refactor commit. For a one-off whole-repo formatting commit, blame.ignoreRevsFile is the better tool.
Further reading: git-blame documentation