python - Finding files with both of two specified terms via git grep -


i'm attempting find files in git repository using git grep , have no easy way of doing without manual searching. have found 1 workaround this:

git grep -l 'term1' | xargs -i grep -l term2 {} 

but i'm wondering if there way similar doesn't require xargs:

git grep -l -e 'term1|term2' 

this means show me files containing either term1 or terms2... there "show me files both these terms."

i'm trying use git grep command in way not practical piping commands other commands. hate working python's subprocess module , use of piping...

two ways achieve goal:

1) combining multiple patterns specified -e option --and flag

--and
--or
--not
( …​ )
specify how multiple patterns combined using boolean expressions.

git grep -l -e 'term1' --and -e 'term2' 

2) using --all-match flag

when giving multiple pattern expressions combined --or, flag specified limit match files have lines match of them.

git grep -l --all-match -e 'term1' -e 'term2' 

https://git-scm.com/docs/git-grep#git-grep--e


Comments