Skip to content

Latest commit

 

History

History
126 lines (86 loc) · 2.45 KB

File metadata and controls

126 lines (86 loc) · 2.45 KB

Episode 7: Git Log Archaeology 🏺

The hidden gem: git log is a full forensic toolkit. Search code changes, trace file history, find who changed what and why.

Beyond git log --oneline

Search commit messages

# Find commits mentioning "search"
git log --grep="search" --oneline

# Case-insensitive
git log --grep="bug" -i --oneline

Search code changes (pickaxe)

# Find commits that ADDED or REMOVED the string "load_tasks"
git log -S "load_tasks" --oneline

# Regex version (more powerful)
git log -G "def cmd_\w+" --oneline

-S (pickaxe) finds commits where the count of a string changed. -G finds commits where the diff matches a regex. These are different and both invaluable.

Trace a function's history

# Show every change to a specific function
git log -L :cmd_add:tasks.py

# Show changes to a line range
git log -L 10,20:tasks.py

This gives you the complete evolution of a function across all commits. Unbelievably powerful.

Follow file renames

# Track a file even after it was renamed
git log --follow --oneline -- tasks.py

Custom log formats

# Compact with author and date
git log --pretty=format:"%h %ad | %s%d [%an]" --date=short

# Graph view of all branches
git log --oneline --graph --all --decorate

# Show only merge commits
git log --merges --oneline

# Show only non-merge commits
git log --no-merges --oneline

Time-based filtering

# Last week's commits
git log --after="1 week ago" --oneline

# Between dates
git log --after="2024-01-01" --before="2024-02-01" --oneline

# By author
git log --author="Alice" --oneline

Diff statistics

# Which files changed in each commit
git log --stat --oneline -5

# Just file names
git log --name-only --oneline -5

# Lines added/removed per file
git log --numstat --oneline -5

Git Blame on Steroids

# Standard blame
git blame tasks.py

# Ignore whitespace changes
git blame -w tasks.py

# Detect moved/copied lines within a file
git blame -M tasks.py

# Detect lines moved from OTHER files
git blame -C tasks.py

# Show blame at a specific commit
git blame <commit> -- tasks.py

Git Shortlog — Release Notes Generator

# Group commits by author
git shortlog -sn

# Group by author with commit messages
git shortlog --no-merges

# Between two tags/versions
git shortlog v1.0..v2.0

Run the Demo

bash episodes/demos/07-log-archaeology-demo.sh