Git Blame: How to Use It, Flags, Editors and What It Misses

Raghav Chamadiya9 min read
On this page

git blame is the Git command that shows, for every line of a file, the commit that last changed it, who made that commit and when. Run git blame <file> to annotate the whole file, or git blame -L 40,60 <file> for a range. It answers "where did this line come from?" in one command.

Blame is the fastest way from a confusing line to the change that introduced it. This guide covers the command and its useful flags, the editor views, how to skip formatting commits, when git log answers the question better, and what blame cannot tell you.

What is git blame?

git blame annotates each line of a file with the last commit that touched it: the short hash, author, date and line number. The name sounds accusatory, but the job is archaeology. You find the commit, then read its message, its diff and the pull request behind it.

bash
git blame src/billing/invoice.py
text
3f9c2a1e (Dana Lee   2026-03-14 10:22:07 +0000  41) def total(self):
3f9c2a1e (Dana Lee   2026-03-14 10:22:07 +0000  42)     subtotal = sum(i.amount for i in self.items)
a71be04d (Sam Ortiz  2026-09-02 16:05:51 +0000  43)     if self.customer.tax_exempt:
a71be04d (Sam Ortiz  2026-09-02 16:05:51 +0000  44)         return subtotal
3f9c2a1e (Dana Lee   2026-03-14 10:22:07 +0000  45)     return subtotal * (1 + self.tax_rate)

Lines 43 and 44 came later. git show a71be04d shows the change that added the tax exemption, with its message. git annotate is the same machinery with an older output format; most people use git blame.

How to use git blame

The base form is git blame <file>; flags narrow the range, skip noise and follow code that moved. These are the ones worth knowing, all from the git-blame documentation.

GoalCommand
Blame a line rangegit blame -L 40,60 path/to/file
Blame from a line, N lines ongit blame -L 40,+10 path/to/file
Blame one functiongit blame -L :total path/to/file
Ignore whitespace-only changesgit blame -w path/to/file
Follow lines moved within the filegit blame -M path/to/file
Follow lines moved or copied from other filesgit blame -C path/to/file (repeat -C up to three times to search harder)
Only commits newer than a dategit blame --since=6.months path/to/file
Blame as of an older commitgit blame v2.3.0 -- path/to/file
Show emails instead of namesgit blame -e path/to/file
Skip one commitgit blame --ignore-rev 3f9c2a1e path/to/file
Machine-readable outputgit blame --porcelain path/to/file

Scroll the table sideways to see every column.

To blame a specific line, pass the same number twice: git blame -L 42,42 path/to/file. -L :funcname takes a regex that matches the function's first line, which saves you counting.

-M and -C matter more than they look. Without them, a function that was moved from utils.py to billing/helpers.py blames entirely on the commit that moved it. With -C, blame looks through the other files changed in that commit and attributes each line to the commit that first wrote it. -C -C also searches the commit that created the file, and -C -C -C searches every commit, which is slow on large histories.

When blame lands on a boring commit, re-run it from that commit's parent: git blame 3f9c2a1e^ -- path/to/file. Repeat until you reach the change with the real reasoning.

Git blame in VS Code, JetBrains, Neovim and GitHub

Every major editor and Git host shows blame inline, so you rarely need the raw command for a single line.

  • VS Code has built-in blame since version 1.96. Turn on git.blame.editorDecoration.enabled for an inline note at the end of the current line, or git.blame.statusBarItem.enabled for the status bar (release notes). The GitLens extension adds a blame gutter, hovers and file history on top.
  • JetBrains IDEs (IntelliJ IDEA, PyCharm, GoLand, WebStorm): right-click the gutter and choose Annotate with Git Blame. Clicking an annotation opens the commit.
  • Neovim: gitsigns.nvim provides :Gitsigns blame_line for the current line and :Gitsigns blame for the file; vim-fugitive provides :Git blame.
  • GitHub: open a file and click Blame. Each block links to its commit, and the "view blame prior to this change" button steps back one commit, the same move as git blame <commit>^. GitLab and Bitbucket have an equivalent view.

To see who changed a file on GitHub as a list instead of per line, click History on the file page; it is git log -- path/to/file in the browser.

Ignore formatting commits with .git-blame-ignore-revs

A .git-blame-ignore-revs file lists commits that blame should look through, so a repo-wide reformat stops hiding the real authors. Without it, one Black, Prettier or gofmt run rewrites the blame of half the codebase.

Create the file at the repository root, one full commit hash per line, with comments:

text
# Reformat the codebase with Black
4a0c8f2d7e1b93c6f5a2d8e0b7c4f1a9e3d6b2c8
# Switch to 4-space indent in the web app
9e1d3b7a5c2f8e4d6a0b9c3e7f1d5a2b8c4e6f0a

Then tell git to use it, once per clone:

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

GitHub's blame view reads a file with exactly this name at the repository root without any setup (GitHub docs). Ignored lines are attributed to the commit before the formatting change. Add the hash after the formatting commit lands, since a squash or rebase changes it.

git blame vs git log -L vs git log -S

Blame shows the last change to each line. git log -L shows every change to a range over time, and git log -S finds the commits that added or removed a string. Pick by the question.

QuestionCommand
Who last changed each of these lines?git blame -L 40,60 file
How did this function evolve, commit by commit?git log -L :total:src/billing/invoice.py
How did lines 40 to 60 change over time?git log -L 40,60:src/billing/invoice.py
When was this string added or deleted anywhere?git log -S "tax_exempt" --oneline
When did a line matching a regex change?git log -G "tax_rate\s*=" --oneline
What changed in this file, newest first?git log -p -- src/billing/invoice.py

Scroll the table sideways to see every column.

git log -L is the underused one. It prints each commit that touched the range with the diff limited to those lines, so you read a function's whole history in one scroll. git log -S (the "pickaxe") is the tool when the line was deleted, because blame only shows lines that still exist.

Why git blame misleads: last touch is not ownership

Blame credits the last person to change a line, which is often not the person who understands it. Four common ways it points at the wrong human:

  1. Mechanical commits. Renames, formatting, import sorting and dependency bumps take over lines. .git-blame-ignore-revs, -w and -C fix most of this.
  2. Squash merges. A squashed pull request credits one author for work several people did.
  3. Small edits on old code. Someone who fixed a typo on line 43 now "owns" it, while the author of the surrounding 200 lines does not show up on that line.
  4. People leave. Blame names the author whether or not they are still on the team.

Blame is the right tool for one line. For "who should review this file" or "who do I ask about this module", you need the file's whole history: how many people wrote it, who wrote most of it, and who has been changing it lately.

That gap is large in real code. Across 195 popular public repos (1,000+ stars, production code only, measured November 2026), the median repo has 60% of its production files with a bus factor of 1, meaning one author made at least 80% of the commits. Pooled, 34% of 20,941 hotspot files, the busiest files, sit with a single author. The bus factor guide explains the measure.

From blame to ownership with repowise

repowise turns blame and commit history into an owner, a bus factor and a knowledge-risk flag for every file, with no setup beyond indexing. In the standard index the primary owner is the author of the most surviving lines by git blame; the bus factor is how many top authors it takes to cover 80% of the file's commits (ownership docs). Commits that only move a file do not count, and .mailmap folds one person's addresses together.

bash
repowise init
repowise risk --target src/auth/session.py      # owner, recent owner, bus factor

The knowledge_loss finding fires when a file is still changing, its bus factor is 1, and the primary owner is no longer the one editing it. That is the case blame cannot show: the code is live and the person who knows it has gone quiet. The same data suggests reviewers for a change from who owns the files it touches, and agents read it through the get_risk and get_context MCP tools.

The git intelligence feature page shows the full view, and you can browse owners and bus factor on a live repo such as django/django. For the method behind it, see code ownership and bus factor from git, and for turning ownership into review rules, the CODEOWNERS file guide.

FAQ

What does git blame do?
git blame shows the commit, author and date that last modified each line of a file. You use it to find the change behind a line, then read that commit's message and diff with git show <hash>. It does not change anything in the repository.
How do I git blame a specific line?
Use -L with the same start and end: git blame -L 42,42 path/to/file. For a range, use -L 40,60, and for a whole function, -L :functionName. In VS Code, JetBrains and GitHub you can click the line instead.
How do I ignore a commit in git blame?
For one run, pass --ignore-rev <hash>. To ignore formatting commits permanently, list their hashes in a .git-blame-ignore-revs file at the repo root and run git config blame.ignoreRevsFile .git-blame-ignore-revs. GitHub's blame view reads that file automatically.
Is there a git praise?
Git has no praise command; git praise returns an error unless you create an alias with git config --global alias.praise blame. Subversion ships svn praise and svn annotate as aliases of svn blame. Git's own alternative name is git annotate.
How do I see who changed a file in GitHub?
Open the file and click History for every commit that touched it, or Blame to see the last commit for each line. In the blame view, the step-back icon next to a block shows the file as it was before that change.