I want to git grep
the files which has two pre-specified words (if both exist, i.e. AND
ing), assume these two words are word1
and word2
I tried
git grep -e 'word1' --and -e 'word2'
And also I tried
git grep 'word1'.*'word2'
but both retrieve the results only if word1
and word2
are on the same line, and the second one does not retrieve if word2
comes first in the line, which is something that I don't want.
I want to retrieve the files, even if the two words are not on same line (I am not sure how many lines separates them, and the order is not important; any order should be fetched).
Is this possible ?
git grep -l word1 | xargs git grep -l word2
... May need to play around with it more if any of your file names contain whitespace or other oddities... – Schindler