Search Tracked Files With git grep
Grep working tree or historical revisions without scanning .git internals.
Run git grep -n "pattern" to search tracked files with line numbers.
01Command
Command
$ git grep -n "TODO" HEAD~502What it does
git grep searches only tracked content, respects .gitignore and can target any commit or tag, so you can compare what a string looked like at different revisions. It is faster than recursive grep over a large checkout.
03Risk
!Warning: Passing an explicit tree like HEAD~5 searches that revision; omitting it searches the working tree.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- git-grep documentationEvidence: Documents git grep, which searches tracked files at a given tree.
Last verified: 2026-10-13 · Category: Developer