An unexpected line in a tracked file can point at the wrong person if the investigation starts from memory or a pull request comment instead of repository history. git blame annotates each current line with the commit and author that last changed it, so a targeted line range shows who introduced the exact text now present in the file.
The -L option limits git blame to one line or a small range instead of printing the entire file. The default output includes an abbreviated commit hash, author name, author date, final line number, and the current line text.
Run the check from a repository that already contains committed history for the file. Uncommitted edits are not attributed to a commit, replaced or deleted lines need history commands such as git log -L or git diff, and large formatting-only commits may need separate review before assigning ownership.
Steps to find who changed a line with git blame:
- Identify the file path and final line number in the current working tree.
- Blame only the target line with -L <line>,<line>.
$ git blame -L 3,3 app.txt 123a27cf (Review User 2026-06-06 09:10:00 +0000 3) status: ready
- Read the commit hash and author from the annotation.
Commit 123a27cf by Review User last changed line 3, whose current text is status: ready.
- Open the blamed commit when the commit message or changed-file summary is needed.
$ git show --stat --oneline 123a27c 123a27c Mark app notes ready app.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
- Repeat the blame command with a wider range when nearby lines need the same ownership check.
$ git blame -L 2,3 app.txt ^15ce003 (Example User 2026-06-06 09:00:00 +0000 2) owner: platform 123a27cf (Review User 2026-06-06 09:10:00 +0000 3) status: ready
The leading caret marks a boundary commit in default blame output. The author and line text still identify where that current line came from.