Terminal GuideTerminal Guide

git blame Command Guide

Show what revision and author last modified each line of a file

5 min readLast updated: January 19, 2026
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

git blame <file>Blame entire file
git blame -L 10,20 <file>Blame lines 10-20
git blame -e <file>Show email addresses

Options

-wIgnore whitespace
-MDetect moved lines
-CDetect copied lines

Format

-sSuppress author name
--date=shortShort date format
--porcelainMachine-readable

Downloadable Image Preview

Failed to generate preview

Basic Usage

The git blame command shows who last modified each line of a file. It's useful for understanding code history and finding the right person to ask about specific code.

bash
# Blame an entire file
git blame src/app.js

# Output shows:
# commit-hash (author date time line-number) content
abc1234 (John Doe 2024-01-15 10:30 1) const app = {
def5678 (Jane Smith 2024-02-20 14:45 2)   name: 'MyApp',

Blaming Line Ranges

bash
# Blame specific line range
git blame -L 10,20 src/app.js

# Blame from line 10 to end
git blame -L 10, src/app.js

# Blame 5 lines starting at line 10
git blame -L 10,+5 src/app.js

# Blame function (if supported)
git blame -L :functionName src/app.js

Common Options

OptionDescription
-L <start>,<end>Annotate only the line range
-eShow author email instead of name
-wIgnore whitespace changes
-MDetect moved lines within file
-CDetect lines copied from other files
-sSuppress author name/time
--date=shortShow short date format

Tracking Code Movement

bash
# Detect moved/renamed lines within file
git blame -M src/app.js

# Detect lines moved from other files
git blame -C src/app.js

# More aggressive copy detection
git blame -C -C -C src/app.js

# Ignore whitespace changes
git blame -w src/app.js

# Combine: ignore whitespace, detect moves/copies
git blame -w -M -C src/app.js

Copy Detection Levels

  • -C - Detect copies from modified files in same commit
  • -C -C - Also look at commits that created the file
  • -C -C -C - Look at all files in any commit

Practical Examples

bash
# Find who wrote a specific function
git blame -L :handleClick src/button.js

# Compact blame output
git blame -s --date=short src/app.js

# Blame at a specific commit
git blame v1.0.0 -- src/app.js

# Find original author (ignoring refactoring)
git blame -w -M -C src/app.js

# Get emails for contacting authors
git blame -e src/app.js

# Machine-readable output for scripts
git blame --porcelain src/app.js

Frequently Asked Questions

How do I blame a specific line range?

Use "git blame -L <start>,<end> <file>". For example: "git blame -L 10,20 app.js" shows blame for lines 10-20.

How do I find the original author of moved/copied code?

Use "git blame -M" to detect moved lines within a file, or "git blame -C" to detect lines copied from other files.

How do I ignore whitespace changes in blame?

Use "git blame -w" to ignore whitespace when comparing commits. This helps find the actual content change, not just reformatting.

Can I blame a file at a specific commit?

Yes! Use "git blame <commit> -- <file>" to see blame as of that commit. This is useful for investigating historical states.

How do I see the full commit message for a blame line?

First get the commit hash from blame output, then use "git show <hash>" or "git log -1 <hash>" to see the full commit details.

Summary

git blame helps you understand code history and find the right person to discuss specific changes with.

Quick Reference

  • git blame <file> - Blame entire file
  • git blame -L 10,20 - Blame line range
  • git blame -w - Ignore whitespace
  • git blame -M -C - Detect moved/copied code

Official Documentation

For authoritative information, refer to the official documentation:

Related Articles