Sub topic 2
Reading git blame output line by line
This chapter assumes you can clone a repository, make commits, and read git log output. You should also be comfortable running commands in a terminal. Here you learn what each column of git blame output means and how to read it without being misled.
What git blame does
git blame shows the commit that last changed each line of a file. It does not tell you who wrote the idea or why. It tells you which commit left the line in its current form. Later chapters build on this, so the reading skills here matter.
Run it on a file:
git blame src/app.pyAnatomy of an output line
Each line of output has the same layout. Here is a sample:
a1b2c3d4 (Maria Lopez 2024-03-18 09:41:12 +0100 42) def parse_config(path):The fields are:
| Field | Example | Meaning |
|---|---|---|
| Commit hash | `a1b2c3d4` | Abbreviated ID of the commit that last changed this line |
| Author name | `Maria Lopez` | The author recorded in that commit |
| Date and time | `2024-03-18 09:41:12 +0100` | The author date, with time zone offset |
| Line number | `42` | Position of the line in the current file |
| Content | `def parse_config(path):` | The line as it exists now |
The hash, author and date all describe one commit. They do not describe the line's first appearance. If a later commit changed one character, that commit owns the whole line.
A worked example
Suppose src/app.py contains this function:
def parse_config(path):
timeout = 30
with open(path) as f:
return load(f, timeout)Blame might produce this output:
a1b2c3d4 (Maria Lopez 2024-03-18 09:41:12 +0100 1) def parse_config(path):
f09e8d7c (Sam Okafor 2025-01-07 16:02:55 +0000 2) timeout = 30
a1b2c3d4 (Maria Lopez 2024-03-18 09:41:12 +0100 3) with open(path) as f:
a1b2c3d4 (Maria Lopez 2024-03-18 09:41:12 +0100 4) return load(f, timeout)Three lines come from Maria's commit a1b2c3d4. Line 2 comes from Sam's commit f09e8d7c. Sam changed that line later, perhaps to adjust the timeout value. To learn why, look at the commit itself:
git show f09e8d7cThe commit message and diff usually explain the intent. Blame only points you to the right commit.
Reading the hash prefixes
Some hashes begin with special characters:
- A leading
^marks a boundary commit. The line has not changed since the start of the history Git is looking at. In a shallow clone, this means the line is older than the history you have, not that it is the original. - A hash of all zeros (
00000000) with the authorNot Committed Yetmarks a line you edited but have not committed.
^3e4f5a6 (Maria Lopez 2023-06-02 11:20:00 +0100 1) import os
00000000 (Not Committed Yet 2026-12-04 15:01:10 +0000 2) import sysSeeing the full picture of a commit
The abbreviated hash is enough for git show. Blame can also show more columns. Two options are worth knowing:
git blame -e src/app.py
git blame --show-name src/app.pyThe -e option shows the author email instead of the name. This is useful when names are inconsistent. The --show-name option adds the file name where the line came from, which matters once you use rename or copy detection in a later chapter.
Author versus committer
Blame reports the author, the person who wrote the change. The committer is the person who applied it to the history. These differ after a rebase, a cherry-pick, or when a maintainer applies a patch from someone else. If you need the committer, run git show --format=fuller <hash>, which prints both.
Common reading mistakes
- Treating the named person as the original author of the logic. They may only have reformatted or renamed something on that line.
- Reading the date as when the code was first written. It is the date of the last change to that line.
- Forgetting that line numbers refer to the current file, not to the file at the time of the commit.
A reformatting commit can take over many lines at once. When you see one author and one date on a large block that looks unrelated to them, suspect a bulk change. Later chapters cover how to see through these.
Exercise
In a blame line, the hash is ^3e4f5a6 and the repository is a shallow clone. What does the leading ^ tell you, and can you conclude the author wrote the line originally?
Show answer
The ^ marks a boundary commit: the line has not changed since the oldest commit Git has available. In a shallow clone the real history is cut off, so the line may be older than that commit. You cannot conclude the named author wrote it originally.
Exercise
A blame line shows 00000000 (Not Committed Yet ...). Why can't you run git show 00000000 to see its history?
Show answer
The line is a local edit that is not in any commit yet, so there is no commit for the hash to point to. Commit the change first, or use git diff to see it.