C.W.K.
Stream
Lesson 05 of 05 · published

git log and git diff: Reading Before Changing

~24 min · log, diff, inspection

Level 0Untracked Rookie
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Read the project before changing it

git log and git diff are how you read a project. Most beginners use them to confirm they did something. Most professionals use them before they do anything: to find when a function changed last, to discover whose code they are about to touch, to scope a change, to verify a hypothesis before pushing.

git log alone is verbose. The shapes worth memorizing: git log --oneline for compact subjects, git log --oneline --graph --decorate --all for the full DAG (alias this — you will use it dozens of times a day), git log -p to see the patches inline, git log --stat for files-changed summary. Filtering: --author, --since/--until, --grep on messages, -S on diff content (pickaxe — finds commits that introduced or removed a string), -G for regex pickaxe.

git diff has more flavors than people realize. git diff alone shows working tree vs index. git diff --staged shows index vs HEAD. git diff abc..def shows commit-to-commit changes. git diff main..feature shows what feature has that main does not (and only that direction). git diff --stat shows a per-file summary. git diff --word-diff highlights changes by word, useful for prose and for diffs in long lines like minified CSS.

Two power moves that pay back forever: git log -p -- path/to/file shows every commit that touched that file with its diff, perfect for tracking down a regression. git log -L :functionName:path/to/file shows the history of just one function across the whole project. The first time you use that on a real bug, you will feel like you found a cheat code.

Code

Daily-grade log incantations·bash
# Compact graph of all branches (alias this!):
git log --oneline --graph --decorate --all

# History of one file with patches:
git log -p -- src/auth.js

# Just one function's history (-L searches by token):
git log -L :authenticateUser:src/auth.js

# Pickaxe — find commits that added or removed a string:
git log -p -S 'OAUTH_ENABLED'

# Filter by author + date range:
git log --author="Pippa" --since="2026-04-01" --oneline
Diff with intent·bash
# Working tree vs index:
git diff

# Index vs last commit:
git diff --staged

# Two commits:
git diff abc1234..def5678

# What does feature have that main does not?
git diff main..feature

# Just file-level summary:
git diff main..feature --stat

# Word-level for prose / long lines:
git diff --word-diff content/cwk-quests/git-quest/data.md

External links

Exercise

Pick a real file in any project that has been edited many times. Run git log --oneline -- path, then pick one commit hash and run git show <hash> -- path. Then run git log -p -S 'someStringYouChosen' -- path. Note what each query revealed that git log --oneline alone did not.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.