iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

git log

git log walks the commit graph. The flags + format options turn it from “dump of commits” into a precise investigation tool. Pair with --graph, --oneline, --all, --author, --grep, -S.

log commands for real investigations

EXAMPLE
# Tidy one-line graph of everything
git log --oneline --graph --decorate --all

# Limit
git log -n 20
git log --since='2 weeks ago' --until=yesterday
git log v1.0..v1.1                  # commits between two refs
git log origin/main..HEAD            # what's in my branch but not main

# By author / committer / message
git log --author='Ada'
git log --grep='regression'
git log --invert-grep --grep='wip'

# By PATH (and changes within it)
git log --oneline -- src/Checkout.tsx
git log -p -- src/Checkout.tsx       # patches included
git log --stat -- src/Checkout.tsx   # per-file summary

# Find when a STRING was added / removed (pickaxe — gold)
git log -S 'window.dataLayer'
git log -G 'TODO:'                   # regex

# By committer / signoff metadata
git log --pretty=format:'%h %ae %s'
git log --pretty=format:'%h | %cn | %ar | %s' --abbrev-commit

# Merges only (or skip them)
git log --merges --oneline
git log --no-merges --oneline --first-parent main

# Reverse + chronological
git log --reverse --oneline

# Side-by-side with diff
git log --patch-with-stat

# Per-branch activity
git log --pretty=format:'%h %an %s' main..feat/checkout

# Identify regression commits using bisect
git bisect start
git bisect bad                       # current commit is bad
git bisect good v1.0                 # v1.0 was good
# git will check out a midpoint; mark each with good/bad
git bisect reset

Why it matters

git log -S (pickaxe) is the most underused investigative tool in the tree. “Who introduced this exact line of code, in what context?” answers in seconds across decades of history.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
git log
git log --oneline --graph --decorate --all
git log -p path/to/file
Try it Yourself »

Discussion

Loading…