Git Grep Multiple Words on Multiple Lines

跟風遠走 提交于 2021-01-02 06:35:36

问题


I want to git grep the files which has two pre-specified words (if both exist, i.e. ANDing), 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 ?


回答1:


Searching multi-line with git-grep is not possible.

Taken from: 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.



来源:https://stackoverflow.com/questions/37304348/git-grep-multiple-words-on-multiple-lines

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!