Git Grep多行多个单词

我想git grep文件有两个预先指定的单词(如果两者都存在,即ANDing),假设这两个单词是word1和word2

我试过了

git grep -e 'word1' --and -e 'word2'

我也试过了

git grep 'word1'.*'word2'

但是只有当word1和word2在同一行上时才检索结果,如果word2在行中排在第一位,则第二个检索结果,这是我不想要的.
我想检索文件,即使这两个单词不在同一行(我不确定有多少行分隔它们,顺序不重要;应该提取任何顺序).
这可能吗 ?

最佳答案 使用git-grep搜索多行是不可能的.

取自:http://git.661346.n2.nabble.com/bug-git-grep-P-and-multiline-mode-td7613900.html

Yes, and deliberately so, to avoid having to think about things like
“how would a multi-line match interact with ‘grep -n’?”

We behave as if we feed each line of the contents one line at a time
to the matching engine that is chosen by the -P/-E/-G/-F options, so
this limitation is unlikely to change.

点赞