gh search code
gh search code <query> [flags]
在 GitHub 代码库中搜索代码。
搜索语法在以下文档中介绍:https://docs.github.com/search-github/searching-on-github/searching-code
请注意,这些搜索结果由现在已成为遗留 GitHub 代码搜索引擎提供。结果可能与 github.com 上显示的结果不匹配,并且像正则表达式搜索这样的新功能尚无法通过 GitHub API 使用。
选项
- 
		--extension <string>
- 按文件扩展名过滤
- 
		--filename <string>
- 按文件名过滤
- -q,- --jq <expression>
- 使用 jq 表达式过滤 JSON 输出
- 
		--json <fields>
- 使用指定的字段输出 JSON
- 
		--language <string>
- 按语言过滤结果
- -L,- --limit <int> (default 30)
- 要获取的代码结果的最大数量
- 
		--match <strings>
- 将搜索限制为文件内容或文件路径:{file|path}
- 
		--owner <strings>
- 按所有者过滤
- -R,- --repo <strings>
- 按代码库过滤
- 
		--size <string>
- 按大小范围(以千字节为单位)过滤
- -t,- --template <string>
- 使用 Go 模板格式化 JSON 输出;请参阅“gh help formatting”
- -w,- --web
- 在网络浏览器中打开搜索查询
JSON 字段
path, repository, sha, textMatches, url
示例
# search code matching "react" and "lifecycle"
$ gh search code react lifecycle
# search code matching "error handling" 
$ gh search code "error handling"
	
# search code matching "deque" in Python files
$ gh search code deque --language=python
# search code matching "cli" in repositories owned by microsoft organization
$ gh search code cli --owner=microsoft
# search code matching "panic" in the GitHub CLI repository
$ gh search code panic --repo cli/cli
# search code matching keyword "lint" in package.json files
$ gh search code lint --filename package.json