Search Historical Changes with Git Pickaxe
Search the change, not the current snapshot
git grep searches content in a selected tree; git log with pickaxe options searches historical differences. Use -S for a literal substring whose occurrence count changes in a file pair. Use -G for a regular expression matching added or removed patch lines. In the history fixture h0 introduces Water every 3 days and h1 changes it to Water every 2 days. Both contain Water every once.
git log --format=%s -S"Water every" -- notes.txtgit log --format=%s -G"Water every" -- notes.txtInterpret the difference carefully
Restrict the comparison to h1 so later rename and path filtering do not confuse the result. -S does not select h1 because the count stays one; -G selects h1 because the removed and added lines match. -S with a more specific string Water every 3 detects its removal at h1. --pickaxe-regex changes -S to regex counting, not -G semantics. Git diff pairing, rename detection, binary files and merge diff selection can affect results.
git log --format=%s -S"Water every" h0..h1 -- notes.txtgit log --format=%s -G"Water every" h0..h1 -- notes.txtgit log --format=%s -S"Water every 3" h0..h1 -- notes.txtInvestigate across a rename
A path-limited history can miss older names. git log --follow continues history for a single path across detected renames, subject to heuristics and history simplification. In the fixture the exact rename h3 preserves content; --follow includes h0–h3, while ordinary path history of garden.txt shows only h3. --all broadens the starting refs but does not restore missing objects or guarantee every historical event is shown.
git log --format=%s -- garden.txtgit log --follow --format=%s -- garden.txtgit show h1 -- notes.txtPractice choosing evidence
To find where a removed string was introduced, start with -S and inspect patches; to find edits to lines matching a pattern, choose -G. To see the current surviving line use blame. To locate a reproducible regression use bisect. Practice: predict both pickaxe results for a change from Water every 2 days to Water every 4 days and explain how you would verify the answer.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Search Historical Changes with Git Pickaxe — knowledge check
Reason about regression and historical evidence.
What does -S detect by default?
Why does -G match h1 but -S Water every does not?
What changes with --pickaxe-regex and -S?
Which option follows one path across detected renames?
Which tool locates a reproducibly failing revision?