如何在 GitHub 上搜索以获取精确的字符串匹配,包括特殊字符 [英] How to search on GitHub to get exact string matches, including special characters

查看:179
本文介绍了如何在 GitHub 上搜索以获取精确的字符串匹配,包括特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用像 "system <<-" 这样的引号从 Google 搜索完全匹配.

I can search exact matches from Google by using quotes like "system <<-".

如何为 GitHub 做同样的事情?

How can I do the same thing for GitHub?

推荐答案

你不能.GitHub官方搜索规则:

You can't. The official GitHub searching rules:

由于搜索代码的复杂性,有一些限制关于如何执行搜索:

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

  • 仅考虑默认分支.在大多数情况下,这将是 master 分支.
  • 只能搜索小于 384 KB 的文件.
  • 只能搜索少于 500,000 个文件的存储库.
  • 在搜索源代码时,您必须始终包含至少一个搜索词.例如,搜索 language:go 是无效的,而 amazing language:go 是.
  • 搜索结果最多可以显示来自同一文件的两个片段,但文件中可能会有更多的结果.
  • 您不能在搜索查询中使用以下通配符:
    <代码>., : ;/` ' "= *!?# $ &+ ^ |~ <>( ) { } [ ]
    搜索将简单地忽略这些符号.
  • Only the default branch is considered. In most cases, this will be the master branch.
  • Only files smaller than 384 KB are searchable.
  • Only repositories with fewer than 500,000 files 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.


克隆并使用git-grep:

git 支持使用 git-grep 在源中搜索命令.只需克隆一个存储库并使用文件夹中的命令:


Clone and use git-grep:

git support searching in sources with git-grep command. Just clone a repository and use the command in the folder:

git grep "text-to-search"

替代方案:

我建议您尝试 ripgrep 工具,它既快速又简单.像 git-grep 一样工作,但看起来更好:

I recommend you to try ripgrep tool, it's fast and simple. Works like git-grep but looks nicer:

rg "text-to-search"

并且您可以使用标准的 grep 来搜索文件中的任何文本:

And you can use the standard grep to search any text in files:

grep -r "text-to-search" /repository

这篇关于如何在 GitHub 上搜索以获取精确的字符串匹配,包括特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆