Git Reference / Inspecting history
05Inspecting history
Browse the log
Many ways to slice history.
git log --oneline --graph --all git log -p path/to/file # patches for one file git log --since="2 weeks ago" --author="Ana" git log main..feature # on feature, not main git log --follow file.js # across renames
Search history (pickaxe)
Find when a string was added or removed.
git log -S "apiKey" # count of string changed git log -G "fetch\(.*\)" # regex in diff git log --grep="hotfix" # commit messages
Look at a commit
Inspect any object.
git show a1b2c3d
git show HEAD~2:src/app.js # file at that commit
git show --stat HEADWho changed this line?
Line-by-line authorship.
git blame app.js
git blame -L 40,60 app.js
git blame -w -C app.js # ignore whitespace, detect movesSearch the code
Fast grep over tracked files.
git grep "TODO"
git grep -n "useState" -- '*.tsx'
git grep "old_api" v1.0 # at a tagStats
Who contributes and how much.
git shortlog -sn git diff --stat main...feature git count-objects -vH