TL;DR –
git log --grep="searches commit messages."
git grepsearches the code itself.$(git rev-list --all)
Add filters (--author,--since,-- path/) or context flags (-p,-S,-G) to zero‑in fast.
Modern repositories can hide tens of thousands of commits. Manually scrolling—or memorising hash IDs—wastes time you could spend shipping code.
Below is a toolkit of six repeatable search patterns that work in any project, whether it’s a fresh micro‑service, a sprawling monorepo, or a decade‑old SVN‑convert.
Why Bother Searching Your Git History?
- Trace when a bug‑causing string first appeared.
- Audit new licenses (e.g. "MIT").
- Track feature toggles or API keys before release.
1 Search Commit Messages Only
# Case‑sensitive
git log --grep="facebook"
# Case‑insensitive + pretty output
git log --all --grep="facebook" -i --pretty="%h %ad | %s" --date=shortTip: Combine multiple patterns with --grep and --invert-grep.
Search Code Changes (Pickaxe)
# Show commits that add or remove the string
git log -S"facebook"
# Regex version (‑G) – useful for variable names
git log -G"facebook_[0-9]+" -p-S compares string counts between parent/child patches; -G runs a regex diff.
Once you've squashed the fix, branch, squash, and fork correctly before opening a pull request.
# Every revision, but only for *.js files
git grep "facebook" $(git rev-list --all) -- '*.js'Add -n (line numbers) or -I (skip binaries) for speed.
Narrow the Search
# Flag Purpose Example
--author limit by committer --author="you@company.com"
--since date lower bound --since="2024-01-01"
--until date upper bound --until="2024-12-31"
-- path/ specific directory -- src/cli/
-i case‑insensitive -iCombine freely:
git log --grep="facebook" --author=alice --since="2 weeks ago" -- src/Quick One‑Liner Cheatsheet
# Search messages
alias glg='git log --all --grep'
# Pickaxe search w/ patch
alias gls='git log -S -p'Save to ~/.gitconfig under [alias] for muscle memory.
And when you’re ready to ship, see our guide on automating your deploy for zero‑downtime releases.
Visual Alternatives
gitk --all --grep – lightweight GUI.
VS Code → Source Control panel → Search Commits extension.
GitHub → repository → Insights → Community → Commits and filter.
Next up → branch, squash, and fork correctly • automate your deploy.
Common Pitfalls
Binary files – add -I (capital‑i) to skip.
Submodules – run in each submodule or use --recurse-submodules (Git 2.13+).
Large repos – prepend LC_ALL=C to speed regex; or restrict with -- path/.
That’s It—Happy Hunting
Spotted something outdated or have a faster trick? Open a PR—or better, join Gun.io and build with engineers who live in their terminal.