Is there a way to make git grep
only match files that I have committed?
The purpose is to grep in the contents of the file, not the log message.
Is there a way to make git grep
only match files that I have committed?
The purpose is to grep in the contents of the file, not the log message.
author="your name"
git log --pretty="%H" --author="$author" | while read commit_hash; do git show --oneline --name-only $commit_hash | tail -n+2; done | sort | uniq |xargs grep -i "String to grep"
OR shorter version:
author="your name"
git log --no-merges --author="$author" --name-only --pretty=format:"" | sort -u |xargs grep -i <string>
Orignal answer used to get the files from a particular user
If you want to grep in the diff of a commit, you should probably use git log -G
or git log -S
:
git log -p --author="your name" -G pattern
Both -G
and -S
will look for the pattern in the diff introduced by a commit,
the difference is (git help log
) :
To illustrate the difference between
-S<regex> --pickaxe-regex
and-G<regex>
, consider a commit with the following diff in the same file:+ return !regexec(regexp, two->ptr, 1, ®match, 0); ... - hit = !regexec(regexp, mf2.ptr, 1, ®match, 0);
While
git log -G"regexec\(regexp"
will show this commit,git log -S"regexec\(regexp" --pickaxe-regex
will not (because the number of occurrences of that string did not change).
When using -p
in conjunction with -G
or -S
, only the files matching the pattern will be displayed.