Git Log Mastery & Forensics
You are now entering advanced forensic investigation training. These skills will help you solve complex mysteries hidden in repository history and track down the source of critical issues.
Commander, every repository tells a story. Within the commit history lies crucial intelligence: who changed what, when, and why. Sometimes missions fail not because of current problems, but because of decisions made months or years ago. The ability to investigate repository history like a detective is what separates elite commanders from those who merely manage code.
You'll master advanced Git log techniques that transform you into a repository archaeologist, capable of extracting precise information from massive codebases, tracking down elusive bugs, and understanding complex development patterns that span years of mission history.
Advanced filtering transforms git log into a precision investigation tool.
# Time-based filtering
git log --since="2 weeks ago" --until="yesterday"
git log --since="2024-01-01"
# Author filtering
git log --author="Sarah"
git log --author="sarah@" # Email match
# Content searches
git log --grep="security" # Search commit messages
git log -S "function_name" # Pickaxe: when code was added/removed
git log -G "pattern" # Regex search in changes
# File-specific
git log --follow -- filename
git log -- "*.js"
# Branch comparisons
git log main..feature # In feature, not in main
git log --graph --oneline --all
Determine who wrote each line and when:
# Basic blame
git blame filename
# With details
git blame -e --date=short filename
# Specific line range
git blame -L 100,120 filename
# From specific commit
git blame abc123f -- filename
Find the exact commit that introduced a bug:
# Start investigation
git bisect start
git bisect bad # Current is bad
git bisect good v1.0 # Known good version
# Test and mark
git bisect good # or bad
# Repeat until Git finds the commit
# Automated
git bisect run npm test
# Finish
git bisect reset
# Top contributors
git log --format='%aN' | sort | uniq -c | sort -nr
# Most modified files
git log --name-only --format='' | grep -v '^$' | sort | uniq -c | sort -nr
# Commits by month
git log --format='%ad' --date=format:'%Y-%m' | sort | uniq -c
# Compact one-liner with graph
git log --oneline --graph --all
# Custom format with colors
git log --pretty=format:"%C(yellow)%h %C(red)%ad %C(blue)%an%C(reset): %s" --date=short
# Detailed format
git log --pretty=format:"Hash: %H%nAuthor: %an <%ae>%nDate: %ad%nSubject: %s%n" --date=iso
# With file statistics
git log --stat --oneline
# Export to CSV
git log --format='"%h","%an","%ae","%ad","%s"' --date=iso > commits.csv
Practice using git bisect to hunt down a performance regression:
# Create test repository
mkdir bug-hunt && cd bug-hunt && git init
# Create fast version
echo "// Fast implementation" > app.js
git add app.js && git commit -m "Fast version" && git tag v1.0
# Add commits
echo "// Feature A" >> app.js && git add app.js && git commit -m "Add feature A"
echo "// Feature B" >> app.js && git add app.js && git commit -m "Add feature B"
# Introduce bug
echo "// SLOW CODE HERE" >> app.js && git add app.js && git commit -m "Refactor"
# More commits
echo "// Feature C" >> app.js && git add app.js && git commit -m "Add feature C"
# Find the bug
git bisect start
git bisect bad # Current is slow
git bisect good v1.0 # v1.0 was fast
# Test each commit Git checks out
# Mark as good or bad until Git finds the culprit
git bisect reset # When done
git log --grep="keyword"
git log -S "code"
git blame file
git bisect start
git log --format='%aN' | sort | uniq -c | sort -nr
git log --follow -- file
# Add to ~/.gitconfig
[alias]
investigate = log --oneline --graph --all
hunt = log --grep
authors = log --format='%aN' | sort | uniq -c | sort -nr
hotfiles = log --name-only --format='' | grep -v '^$' | sort | uniq -c | sort -nr
You've mastered advanced Git history analysis and forensic techniques.