Sample output
a1c3e7f Remove legacy auth middleware
f4d219b Refactor login flow to use OAuth
83b6a02 Add handleAuth function for session tokens
Three commits touched the string handleAuth. Read from the bottom up: 83b6a02 added it, f4d219b changed how many times it appeared, and a1c3e7f removed it entirely. Run git show a1c3e7f to see exactly what was deleted.
When you would reach for it
Someone removed a function or a config block and nobody remembers when or why. A test references a helper that no longer exists. You are tracking down when a feature flag was introduced or retired. The pickaxe answers “which commit changed the presence of this string” across the entire history, which is a different question from grep and one that is harder to answer any other way.
Gotchas
-Scounts occurrences, so a commit that renameshandleAuthtohandleAuthenticationwill show up twice: once for removing the old string, once for adding the new one. If that is confusing, use-G"handleAuth"instead, which matches any diff line containing the pattern.- On large repositories the search can be slow because Git walks every commit and diffs every changed file. Adding a path at the end (
git log -S"handleAuth" --oneline -- src/auth/) narrows the search to one directory and speeds it up considerably. - The string match is literal by default. If you need a regex, use
-Ginstead of-S. The two flags are not interchangeable:-Scounts occurrences per file,-Ggreps diff lines. --allincludes stash refs and remote-tracking branches. If the output is noisy, drop--alland search only the current branch.
Variants
$ git log -S"handleAuth" -p --all -- src/
Show the full diff for each matching commit, scoped to the src/ directory. Useful when you need to see the surrounding code, not only the commit message
$ git log -G"handle[A-Z].*auth" --oneline --all
Regex search across diffs. Finds any line where a pattern was added or removed, regardless of exact spelling
$ git log -S"handleAuth" --oneline --all --diff-filter=D
Show only commits that deleted a file containing the string. Narrows the results when you know the whole file was removed, not a single function