Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Inspecting History

git log -S and -G options (pickaxe)

Reference for the git log pickaxe options -S, -G, --pickaxe-regex and --pickaxe-all: find the commit that added, removed or changed a string or pattern.

The pickaxe options of git log search the changes of each commit rather than the commit messages or the current files. They answer questions such as "When did TIMEOUT disappear from this code?" or "Which commit introduced a call to legacy_login()?".

Two options do the job and they differ in a subtle way. -S<string> keeps commits where the number of occurrences of the string in a file changed. -G<regex> keeps commits whose diff has an added or removed line matching the regular expression. The same options exist for git diff and git show.

Terminal
git log -S<string> [--pickaxe-regex] [--pickaxe-all] [-p] [-- <path>]
git log -G<regex> [-p] [-- <path>]

Try it

Bash -S counts occurrences, -G matches changed lines

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Regex with -S, and seeing the change

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Option Description
-S<string> Show commits where the number of occurrences of <string> differs between the two sides of the diff. Written without a space, or as -S <string>.
-G<regex> Show commits whose patch has an added or removed line matching <regex> (POSIX extended; PCRE with --perl-regexp).
--pickaxe-regex Treat the argument of -S as an extended regular expression.
--pickaxe-all When a commit matches, show the changes of all files in it, not only the matching file.
-i, --regexp-ignore-case Case-insensitive matching for -G and -S --pickaxe-regex.
-p Show the patch so you can see the matching change.
-- <path> Limit the search to paths.

Both options work with git diff as well, for example git diff -S TIMEOUT v1.0 v2.0.

Usage notes

  • -S finds where something was added or removed. A commit that moves the string from one place to another in the same file keeps the count equal and is not listed. That is a feature when you hunt for the introduction or deletion of an identifier.
  • -G finds where lines containing the pattern changed, including edits that keep the count the same. It is the better choice when you do not know whether the thing was added, removed or edited, and it supports patterns like -G'timeout\s*='.
  • -G runs the regex on diff lines, so it cannot match across lines; a multi-line pattern needs -S with a literal string.
  • Pickaxe examines the contents of every commit it walks, so it is slower than message searches such as --grep. Narrow with a path, a revision range or --since.
  • Combine with --all to search every branch.
  • To trace a function or line range instead of a string, use git log -L :name:file.
  • Merge commits are not matched by default; add -m or --first-parent if the change arrived only via merge conflict resolution.