The hidden gem:
git logis a full forensic toolkit. Search code changes, trace file history, find who changed what and why.
# Find commits mentioning "search"
git log --grep="search" --oneline
# Case-insensitive
git log --grep="bug" -i --oneline# 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.
# 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.pyThis gives you the complete evolution of a function across all commits. Unbelievably powerful.
# Track a file even after it was renamed
git log --follow --oneline -- tasks.py# 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# 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# 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# 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# 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.0bash episodes/demos/07-log-archaeology-demo.sh