Skip to content

Instantly share code, notes, and snippets.

@eminarcissus
Forked from lyoshenka/search-git-history.md
Created February 7, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eminarcissus/bfe9203bd0496fc8c7e1f5bd3fb119fc to your computer and use it in GitHub Desktop.
Save eminarcissus/bfe9203bd0496fc8c7e1f5bd3fb119fc to your computer and use it in GitHub Desktop.
Search Git commit history for a string and see the diffs

Searching Git commit history

This should be one of the core features of Git, but for some reason it's impossible to figure out how to search for a string in your commit history and see the diffs that that string is in. Here's the best I've come up with:

To find which commits and which files a string was added or removed in:

git log -S'search string' --oneline --name-status

To see the diff of that

git log -S'search string' -p | grep 'search string' -C5

You can also do a regex search by using -G instead of -S.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment