bashintermediate

Git Blame Investigation Techniques

Use git blame and related tools to trace code authorship and understand change history.

bash
# Basic blame — show who changed each line
git blame src/lib/registry.ts

# Blame with line range
git blame -L 10,30 src/lib/registry.ts

# Ignore whitespace changes
git blame -w src/lib/registry.ts

# Show original author (ignore moved/copied lines)
git blame -M src/lib/registry.ts     # detect moves within file
git blame -C src/lib/registry.ts     # detect moves from other files
git blame -CCC src/lib/registry.ts   # aggressive copy detection

# Show email instead of name
git blame --show-email src/lib/registry.ts

# Blame at a specific commit
git blame abc1234 -- src/lib/registry.ts

# Find when a line was deleted
git log -S "deleted function name" --oneline

# Find when a line was added/removed with regex
git log -G "pattern" --oneline

# Show the commit that introduced a line
git log -1 abc1234
git show abc1234

# GUI blame
git gui blame src/lib/registry.ts

# List files changed by author
git log --author="Alice" --name-only --pretty=format: | sort -u

Use Cases

  • Finding who introduced a bug
  • Understanding code history and context
  • Tracing when a specific change was made

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.