How to grep in commits of specific author(s) with git (i.e., w/o piping to grep
)?
I could use git log
and pipe into grep
, but maybe there's a better (faster?) way?
git log --author="John Doe <jdoe@host>" -p | grep "some interesting stuff"
As a @Guildenstern says, you don't need to use git grep
, you just need to add --grep
flag to your git log
command, like this:
git log --author=<something> --grep=<something>
This grep flag will search only within commit messages. If you need to search in the diff (e.g., some string that was added or removed in the change) you can use the -S
flag, like this:
git log --author=<something> -S'changes'
And if you need to search by regex you can use -G
flag, like this:
git log --author=<something> -G'^changes'
This will find any changes in the diff that contain a line starting with changes
.
For more information about the differences between the -S
and -G
flags you can check here (thanks @j6t):
https://git-scm.com/docs/git-log#Documentation/git-log.txt--Gltregexgt
A few more interesting examples
Find commits from multiple authors
git log --author=<something> --author=<someone>
Use multiple grep flag:
git log --author=<something> --grep=fix --grep=feat
If you need to find a commit that contains both words in a single commit message, add the --all-match
flag, like this:
git log --author=<something> --grep=fix --grep=feat --all-match