How does git blame work, and what kind of question does it help you answer?
Last updated
git blame annotates each line of a file with the commit, author, and date that last modified it, answering "who changed this line and when (and in which commit)?"
What it shows:
For every line: the short commit hash, author, timestamp, and the line content.
It reports the last commit that touched each line, not the full history of that line.
What question it answers:
Great for context/archaeology: find the commit behind a suspicious line, then read its message or
git showto learn why.It's an investigative tool, not a blame-assignment tool despite the name.
Useful options:
-L 10,20limits output to a line range.-wignores whitespace changes;-Cand-Mdetect lines moved or copied across files so a reformat doesn't hide the real author.
Follow-up: to see how a line evolved over time, pair blame with
git log -Lor the interactivegit gui blame.
[lang:bash]
git blame -L 30,40 -w src/app.py
git show <hash> # inspect the commit blame pointed to
- https://git-scm.com/docs/git-blame
- https://www.git-tower.com/learn/git/faq/git-blame
- https://rse.shef.ac.uk/blog/git-blame/
- https://docs.github.com/en/repositories/working-with-files/using-files/viewing-and-understanding-files
- https://www.atlassian.com/git/tutorials/inspecting-a-repository/git-blame
- https://www.freecodecamp.org/news/git-blame-explained-with-examples/
- https://medium.com/@ruqaiya.beguwala/day-7-30-git-blame-l-see-who-changed-a-specific-line-in-a-file-20845bdf052d
- https://gitbybit.com/gitopedia/git-commands/git-blame