git log and git diff are powerful tools for inspecting history and changes, with many options for filtering, formatting, and comparing. Knowing how to use them effectively helps you understand a codebase's evolution and review changes precisely.
git log — exploring history
git log --oneline # compact (one line per commit)
git log --oneline --graph --all # visual branch graph of ALL branches
git log -p # show the DIFF of each commit (patches)
git log --stat # files changed + insertion/deletion counts
# FILTERING
git log --author="Ann" # commits by an author
git log --since="2 weeks ago" # by date
git log --grep="login" # commits whose MESSAGE matches
git log -S"functionName" # commits that ADDED/REMOVED this code (pickaxe!)
git log <file> # history of a specific file
git log main..feature # commits on feature not in main
The pickaxe (-S) is especially powerful — it finds commits that introduced or removed a specific string, great for tracing when code appeared.
git diff — comparing changes
git diff # working dir vs staged (unstaged changes)
git diff --staged # staged vs last commit (what will commit)
git diff HEAD # all changes vs the last commit
git diff main feature # differences between two branches
git diff <commit1> <commit2> # between two commits
git diff <commit> -- <file> # changes to a specific file
git diff --word-diff # word-level (not line-level) diff
Useful combinations
git log --oneline --graph --all → visualize the whole branch structure
git log -p -- <file> → full change history of a file (with diffs)
git log --follow <file> → file history across renames
git blame <file> + git show <commit> → who/when/why a line changed (trace context)
Why it matters
Understanding how to use git log and git diff effectively is valuable for inspecting history and changes, a frequent need in development, so it's useful practical Git knowledge. git log is how you explore a project's history — and knowing its options transforms it from a basic list into a powerful investigation tool: formatting (--oneline, --graph for visualizing branch structure, --stat for change summaries), and especially filtering (by author, date, commit message with --grep, by file, by branch range, and the powerful pickaxe -S that finds commits which added or removed specific code — invaluable for tracing when a piece of code appeared or vanished).
These let you efficiently answer real questions like "who changed this and when", "what changed in the last release", or "when was this function introduced". git diff is how you examine changes precisely — comparing the working directory, staging area, commits, and branches — essential for reviewing what you're about to commit (--staged), comparing branches, and understanding differences.
Knowing useful combinations (visualizing branch structure, tracing a file's full history with --follow across renames, combining blame and show to understand why a line changed) reflects effective investigation skills.
Since understanding a codebase's evolution and reviewing changes are constant needs (for debugging, code review, understanding history, and tracing changes), and since git log and git diff with their powerful options are the primary tools for this, understanding how to use them effectively — log's formatting and filtering (especially the pickaxe), diff's comparisons, and useful combinations — is valuable, frequently-applied Git knowledge that turns history inspection from guesswork into precise investigation, a useful skill for understanding and navigating any codebase's development.
