# Git Blame: who last changed each line

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/git-blame-full-en
`git blame FILE` prints, for every line, the commit that last changed it. `-L START,END` limits the output to a line range, and `-L START,+COUNT` limits it to COUNT lines from START.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 3 tests were run, TE-60-A, TE-60-B and TE-60-C. The expected non-zero exit is TE-60-C (exit status 128). Every row has a recorded log, and the exit statuses and log hashes are in the evidence table.)

### TE-60-A: blame -L attributes a single line to the commit that last changed it

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\nb\n' > f.txt; git add f.txt; git commit -qm first
printf 'a\nB\n' > f.txt; git commit -qam second
```

Command:

```bash
git blame -L 1,1 --porcelain f.txt | grep '^summary'; git blame -L 2,2 --porcelain f.txt | grep '^summary'
```

Recorded output:

```
summary first
summary second
```

Exit status: 0. The output matches the expected text written before the run. This is the status of grep, the last command in the pipe.

### TE-60-B: blame -L with a start and a line count (2,+1) attributes the second line to its commit

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\nb\n' > f.txt; git add f.txt; git commit -qm first
printf 'a\nB\n' > f.txt; git commit -qam second
```

Command:

```bash
git blame -L 2,+1 --porcelain f.txt | grep '^summary'
```

Recorded output:

```
summary second
```

Exit status: 0. This status and the output match what was written before the run. The status is that of grep, the last command in the pipe.

### TE-60-C: expected non-zero exit: git blame on a path that is not in HEAD stops with a fatal error

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
```

Command:

```bash
git blame nosuch.txt
```

Recorded output: none, standard output was empty.

Standard error from the same run:

```
fatal: no such path 'nosuch.txt' in HEAD
```

Exit status: 128. This status and the output match what was written before the run.

TE-60-B: by the setup, the second line was changed by the commit named second. -L 2,+1 selected one line starting at line 2, and the summary line reads summary second. TE-60-C: git blame nosuch.txt exited with status 128, and standard error reads fatal: no such path 'nosuch.txt' in HEAD.

## Limits

Blame names the last commit that touched a line, which may not be the commit that introduced the idea. Moved or copied lines (`-M`, `-C`) were not tested.

## Source

- https://git-scm.com/docs/git-blame

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-60-A` | blame -L attributes a single line to the commit that last changed it | 0 | PASS | `3176f379c4e1` |
| `TE-60-B` | blame -L with a start and a line count (2,+1) attributes the second line to its commit | 0 | PASS | `dfdc9dee5570` |
| `TE-60-C` | expected non-zero exit: git blame on a path that is not in HEAD stops with a fatal error | 128 | PASS | `be922f84c927` |

Recorded on: bash 5.1.16(1)-release; git version 2.34.1; Python 3.10.12. Locale C.UTF-8, TZ=UTC.
Every row has a recorded log holding the setup commands, the command, stdout, stderr and exit status. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [Git Branch Delete: -d versus -D](https://kairos-2z6s.onrender.com/res/git-branch-delete-full-en)
- [Git Stash: set aside uncommitted work](https://kairos-2z6s.onrender.com/res/git-stash-full-en)
- [Git Config Get: read one setting](https://kairos-2z6s.onrender.com/res/git-config-get-full-en)
- [git bisect: find the commit that broke something](https://kairos-2z6s.onrender.com/res/git-bisect-full-en)
- [Git Commit Allow Empty: a commit with no changes](https://kairos-2z6s.onrender.com/res/git-commit-allow-empty-full-en)
