git blame
Show which commit and author last modified each line of a file, tracking down when changes were made.
You're looking at a confusing piece of code and wondering who wrote it and why.
git blame shows which commit last modified each line of a file, displaying the
commit SHA, author, date, and line content. Despite the name, it's not about
assigning fault—it's about finding context for code by connecting it to the
commit and author who can explain it.
Running git blame filename.js displays the file with annotations showing who
last touched each line. If line 42 was added in commit abc123 by Alice on March
15, that information appears next to the line. This helps you understand the
history of specific code sections and find the right person to ask questions.
The -L flag limits blame to specific line ranges: git blame -L 10,20 file.js
shows only lines 10 through 20. This narrows the output when you're
investigating a particular function or block of code. You can also use function
names with some languages: git blame -L :functionName file.js.
Adding -w ignores whitespace changes, so reformatting doesn't obscure who made
substantive changes: git blame -w file.js. The -C flag detects code moved or
copied from other files, showing where the code originally came from rather than
just who moved it.
In pull request workflows, blame helps during code review when you need more
context about existing code. If a PR modifies a function and you're unsure about
its original purpose, blame shows the commit that added it. You can then use
git show on that commit to see the full change and commit message explaining
why it was written that way.
Understanding blame means having a tool to answer "why is this code here?" by finding the commit that introduced it. The commit message and surrounding changes provide context that helps you make informed decisions when modifying code or investigating bugs.
