如何在github上搜索以获得完全匹配(就像Google的报价一样)

How to search on github to get exact matches (like what quotes do for Google)

我可以使用像"system <<-"这样的引号从谷歌中搜索完全匹配的内容。如何为Github做类似的事情?我做不到。


不能。Github官方搜索规则:

Due to the complexity of searching code, there are a few restrictions
on how searches are performed:

  • Only the default branch is considered. In most cases, this will be the master branch.
  • Only files smaller than 384 KB are searchable.
  • You must always include at least one search term when searching source code. For example, searching for language:go is not valid, while amazing language:go is.
  • At most, search results can show two fragments from the same file, but there may be more results within the file.
  • You can't use the following wildcard characters as part of your search query:
    . , : ; / \ ` '" = * ! ? # $ & + ^ | ~ < > ( ) { } [ ]
    The search will simply ignore these symbols.

解决办法:

如果需要在单个存储库中搜索,可以在本地克隆它,并使用grep精确查找字符串:

1
grep -r"system <<-" /repository_dir


你可以直接使用谷歌。

这个怎么样?

1
2
"your_string_to_search" site::https://github.com
"your_string_to_search" site::https://gist.github.com


今天我在Github上的任何一个repo文件中,都试图寻找一个与filter class完全匹配的文件logback.xml。我提出了下面的问题,完成了这项工作。

1
"filter class" in:file filename:logback.xml

要使用引号进行精确匹配,您需要使用"in:file"修饰符进行搜索。匹配不太精确,"class"这个词必须跟在"filter"后面,但两个词之间似乎可以有0个或更多的空格或符号字符。


如果您的包在Debian中,您可以使用它们的代码搜索,它支持正则表达式:https://codesearch.debian.net/