To search for code, use the following search qualifiers in any combination.
Tip: There's a list of search syntaxes you can add to any search qualifier to further improve your results.
Considerations for code search
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, whileamazing 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.
以上是代码搜索中需要注意的一些问题
默认搜索是从master分支搜索代码
只有小于384k的代码才是可以搜索到的
搜索的时候必须包含至少一个搜索关键词 如 amazing language:go
搜索语句不能有特殊字符如. , : ; / \ ` ' " = * ! ? # $ & + ^ | ~ < > ( ) { } [ ]
.
Scope the search fields
指定搜索方式
Search by language
通过语言搜索代码
You can search for code based on what language it's written in. For example:
Search by the number of forks the parent repository has
通过fork的数量或者是否有父节点的方式搜索
If you would like forked results to appear, add the fork:true qualifier. For example:
The size qualifier filters results based on the size of the file in which the code is found. For example:
Search by the location of a file within the repository
按照目录结构搜索
By including the path qualifier, you specify that resulting source code must appear at a specific location in a repository. Subfolders are considered during the search, so be as specific as possible. For example:
Search by filename
通过文件名搜索
You can use the filename qualifier if there's a specific file you're looking for. For example:
Search by the file extension
根据扩展名来搜索代码
The extension qualifier matches code files with a certain extension. For example:
Search within a user's or organization's repositories
通过用户或者组织来查找
To grab a list of code from all repositories owned by a certain user or organization, you can use the user syntax. For getting a list of code from a specific repository, you can use the repo syntax. For example: