git blame
On this page you can find useful information about git blame command, as well as how it works with examples, and see the list of the most common options.
Description
The git blame command annotates each line of a file with information about the last commit that changed it — the commit hash, the author, and the timestamp. In other words, for every line it answers the question "who wrote this, and when?".
It is a read-only inspection command. It does not change history or files; it only displays metadata that already lives in the repository. Developers reach for git blame to:
- Find the author of a confusing or buggy line so they can ask about the intent behind it.
- Locate the commit that introduced a change, then read its full message with git show.
- Understand how a file evolved when the commit history alone is too coarse to point at a single line.

git blame shows only the most recent commit that touched each line. If a line was edited several times, earlier authors are hidden. To follow a line further back in time, re-run blame on an older revision (see Following a line through history below).
How it works
To clearly show how git blame works, let’s consider an example where we have a README.md file with a few commits from different authors.
In the following example, we use git blame. The state of the example repository can be explored with a git log. The commit history looks like this:
git log and git blame
git log
commit 745a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a
Author: Bob Smith <[email protected]m>
Date: Fri Apr 1 19:55:15 2019 +0000
Another commit to help git blame track the who, the what, and the when
commit eb06faedb1fdd159d62e4438fc8dbe9c9fe0728b
Author: Bob Smith <[email protected]m>
Date: Fri Apr 1 19:53:23 2019 +0000
Creating the third commit, along with Nick and Robert, so that Nick can get git blame docs.
commit 990c2b6a84464fee153253dbf02e845a4db372bb
Merge: 82496ea 89feb84
Author: Tom Brown <[email protected]m>
Date: Fri Apr 1 05:33:01 2019 +0000
Merged in tom-brown/git-blame-example/albert-so/readmemd-edited-online-with-bitbucket-1519865641474 (pull request #2)
README.md edited online with Bitbucket
commit 73a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8
Author: Tom Brown <[email protected]m>
Date: Fri Apr 1 00:54:03 +0000
README.md edited online with BitbucketThe git blame command works on individual files. The default execution of git blame outputs the blame information for the specified file.
The following output is a subset of the full blame output of the README file:
git blame
git blame README.md
83253a1b (marioswift 2019-02-28 13:37:02 -0800 1) # Git Blame example
83253a1b (marioswift 2019-02-28 13:37:02 -0800 2)
73a0b1c2 (Tom Brown 2019-04-01 00:54:03 +0000 3) Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.
83253a1b (marioswift 2019-02-28 13:37:02 -0800 4)
83253a1b (marioswift 2019-02-28 13:37:02 -0800 5) There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable.
83253a1b (marioswift 2019-02-28 13:37:02 -0800 6)
73a0b1c2 (Tom Brown 2019-04-01 00:54:03 +0000 7) Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod TEMPOR incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laborum nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborumReading the output
Each blame line is built from four parts:
83253a1b (marioswift 2019-02-28 13:37:02 -0800 1) # Git Blame example
└──┬───┘ └───┬────┘ └────────┬─────────────┘ │ └──────────┬──────────┘
│ │ │ │ └─ the line's content
│ │ │ └─ line number in the file
│ │ └─ commit timestamp
│ └─ author of that commit
└─ abbreviated commit hashLines that share the same commit hash were last changed together. To inspect what that commit actually did, copy the hash and run git show 83253a1b.
Common Options
git blame accepts several options that narrow the output or change how authorship is attributed. The most useful ones are summarized below.
| Command | What it does |
|---|---|
git blame -L 1,3 README.md | Limits the output to the requested line range — here, lines 1 through 3. You can also use -L 5,+10 to start at line 5 and show 10 lines. |
git blame -e README.md | Shows each author's email address instead of their username. |
git blame -w README.md | Ignores whitespace-only changes. If a previous author only re-indented a line (e.g. tabs to spaces), git blame would otherwise credit them; -w looks past it to the real content change. |
git blame -M README.md | Detects lines that were moved or copied within the same file, and reports the original author instead of whoever moved them. |
git blame -C README.md | Detects lines that were moved or copied from other files, and reports the original author. Pass -C two or three times for a more aggressive search. |
git blame -L :functionName README.md | Limits blame to a single function by name (uses Git's funcname regex), instead of a numeric line range. |
Following a line through history
Because blame stops at the most recent commit per line, you sometimes need to dig one step deeper. Once you have the commit hash from the blame output, you can re-run blame on the commit before that one to see what the line looked like — and who wrote it — earlier.
# Blame the file as it was just before commit 73a0b1c2 touched it
git blame 73a0b1c2^ -- README.mdThe ^ (caret) means "the parent of this commit". Repeating this lets you walk a line backwards through its full history, one revision at a time.
You can also restrict blame to a revision range so you only see authorship from a particular slice of history:
# Blame README.md considering only commits between v1.0 and v2.0
git blame v1.0..v2.0 -- README.mdGit Blame vs Git Log
The git blame command shows the last author who changed a line, but sometimes you may need to see when a line was initially added. That is awkward with git blame alone — even with a combination of the -w, -C, and -M options. For tracking when a piece of text first appeared (or was removed), git log is the better tool.
Use git log with the -S option (the "pickaxe") to display commits where a specific string was added or removed.
Example: finding when a string changed
git log -S example
git log -S "CSS3D and WebGL renderers." --pretty=format:'%h %an %ad %s'
e339d3c85a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d John Carter Fri Jun 13 16:51:06 2015 +0200 reverted README.md to original content
509c2cc35a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d Max Fri Jul 8 13:56:14 2015 +0200 Updated README
cb20237cc1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6 Leo Sat Aug 31 00:22:36 2012 +0100 Removed DOMRenderer. Now with the CSS3DRenderer it has become irrelevant.The output shows that the README.md file was added and modified 3 times by three authors. The --pretty=format:'...' option customizes the git log output to display specific fields like commit hash, author, date, and subject.
Related commands
git blame is most useful alongside other inspection commands:
- git log — browse the full commit history and search it with
-S/-G. - git show — display the full message and diff of a commit you found via blame.
- git diff — compare the line's current state with an earlier revision.