Skip to content

Instantly share code, notes, and snippets.

@aeinbu
Last active November 11, 2025 14:58
Show Gist options
  • Select an option

  • Save aeinbu/7242425f954cb21d28074e079fb17559 to your computer and use it in GitHub Desktop.

Select an option

Save aeinbu/7242425f954cb21d28074e079fb17559 to your computer and use it in GitHub Desktop.

Different ways to search a git repo

Search commit messages

git log --grep="..."

Search all file contents

git log -S "..."
git log -S "..." --pickaxe-regex
git log -G "..."

See docs for

  • git log -S \<string> will look for the commits that changes the number of occurrences. This will find when something was added or removed, but not just moved to somewhere else inside the same commit.
  • git log -S \<regex> --pickaxe-regex Same as above, but with regex support
  • git log -G \<regex> will look for the commits where a change involves this regex or text. It will find when it has been moved, as well as added or removed.

Limit search to specific file(s)

git log -- "exact/path/to/filename.js"
git log -- ":(icase)*/filename.js"
git log --follow -- "exact/path/to/filename.js"
  • git log -- "<exact/path/to/filename>" - After the -- part, you can narrow down the search to specific filename(s). (NOTE: Remember the space after --.)
  • git log -- ":(icase)*<partial-path-or-filename>*" - Wildcards are allowed. The :(icase) part makes the filename case insensitive.
  • git log --follow -- "<exact/path/to/filename.js>" - The --follow part will find the same file also after it has been renamed. Doesn't work with wildcards or case insensitive searches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment