Skip to main content

关于 GitHub 代码搜索

可以使用代码搜索在 GitHub 中进行搜索、导航和了解代码。

GitHub code search lets you rapidly search, navigate and understand your code, your team's code, and the code of the open source community. This search engine is designed to be scalable, code-aware, and support searching code across GitHub using regular expressions, boolean operations, specialized qualifiers, and symbol search. For more information on the syntax of code search, see "Understanding GitHub Code Search syntax."

Code search is integrated with features in the search interface on GitHub.com, such as suggestions and completions. Your searches will be saved automatically and can be deleted at any time. On GitHub Mobile, you can use the same methods to search through code directly from the home screen. For more information, see "Using GitHub Code Search."

You must be logged in to a GitHub account to use code search, including for searching code in public repositories.

Note that the syntax and qualifiers for searching for non-code content, such as issues, users, and discussions, is not the same as the syntax for code search. For more information on non-code search, see "About searching on GitHub" and "Searching on GitHub."

Limitations

We have indexed many public repositories for code search, and continue to index more. Additionally, the private repositories of GitHub users are indexed and searchable by those that already have access to those private repositories on GitHub.com. However, very large repositories may not be indexed at this time, and not all code is indexed.

The current limitations on indexed code are:

  • Vendored and generated code is excluded
  • Empty files and files over 350 KiB are excluded
  • Lines over 1,024 characters long are truncated
  • Only UTF-8 encoded files are included
  • Very large repositories may not be indexed
  • Exhaustive search is not supported

We currently only support searching for code on the default branch of a repository. The query length is limited to 1000 characters.

Results for any search with code search are restricted to 100 results (5 pages). Sorting is not supported for code search results at this time. This limitation only applies to searching code with the new code search and does not apply to other types of searches.

If you use the path: qualifier for a file that's in multiple repositories with similar content, GitHub will only show a few of those files. If this happens, you can choose to expand by clicking Show identical files at the bottom of the page.

Code search supports searching for symbol definitions in code, such as function or class definitions, using the symbol: qualifier. However, note that the symbol: qualifier only searches for definitions and not references, and not all symbol types or languages are fully supported yet. For a list of what languages are supported, see "Understanding GitHub Code Search syntax."

On GitHub Mobile, you can use code search directly from the home screen. For more information, see "Using GitHub Code Search."

Feedback and support

You can view and share feedback about code search in our discussion forum.