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
.
On that same StackOverflow issue that @raedbenz linked, there is a better answer that basically suggests the same
-S
'pickaxe' method described here + goes into some more details about it's usage:Since I always find myself ending up back on this gist, here are the methods described in that StackOverflow:
Looking at the StackOverflow for case-insensitive pickaxes search:
From:
You can combine
-p
/--patch
with any of these methods to get a diff patch of the found commits.Hopefully saves someone else (or future me) some time! 🖤