Github 搜索语法大全

博客介绍了GitHub搜索语法的限制,如查询长度不能超过256个字符,不能使用超过五个特定运算符等,还提及了搜索仓库、代码、用户等参考内容,且表示内容未完待续。

搜索语法限制

  • Queries longer than 256 characters are not supported
  • You can't construct a query using more than five AND, OR, or NOT operators

 

参考

Searching for repositories

限定符示例说明
in

jquery in:name

jquery in:name,description

jquery in:readme

搜索名字中包含关键字的信息

所搜名字或描述中包含关键字的信息

搜索readme中包含关键字的信息

useruser: USERNAME根据用户名进行搜索
orgorg: ORGNAME org:github matches repositories from GitHub.
sizesize: n size:1000 matches repositories that are 1 MB exactly.
size:>=30000 matches repositories that are at least 30 MB.
size:<50 matches repositories that are smaller than 50 KB.
size:50..120 matches repositories that are between 50 KB and 120 KB.
forksforks: n forks:5 matches repositories with only five forks.
forks:>=205 matches repositories with at least 205 forks.
forks:<90 matches repositories with fewer than 90 forks.
forks:10..20 matches repositories with 10 to 20 forks.
starsstars: n stars:500 matches repositories with exactly 500 stars.
stars:10..20 matches repositories 10 to 20 stars, that are smaller than 1000 KB.
stars:>=500 fork:true language:php matches repositories with the at least 500 stars, including forked ones, that are written in PHP.
created created: YYYY-MM-DD webos created:<2011-01-01 matches repositories with the word "webos" that were created before 2011.
pushed pushed: YYYY-MM-DD

css pushed:>2013-02-01 matches repositories with the word "css" that were pushed to after January 2013.

case pushed:>=2013-03-06 fork:only matches repositories with the word "case" that were pushed to on or after March 6th, 2013, and that are forks.

languagelanguage: LANGUAGE rails language:javascript matches repositories with the word "rails" that are written in JavaScript.
topic

topic: TOPIC

topics: n

topic:jekyll matches repositories that have been classified with the topic "jekyll."

topics:5 matches repositories that have five topics.

topics:>3 matches repositories that have more than three topics.

licenselicense: LICENSE_KEYWORD license:apache-2.0 matches repositories that are licensed under Apache License 2.0.
is

is:public

is:private

is:public org:github matches repositories owned by GitHub that are public.

is:private pages matches private repositories you have access to and that contain the word "pages."

mirror

mirror:true

mirror:false

mirror:true GNOME matches repositories that are mirrors and contain the word "GNOME."

mirror:false GNOME matches repositories that are not mirrors and contain the word "GNOME."

achieved

archived:true

archived:false

archived:true GNOME matches repositories that are archived and contain the word "GNOME."

archived:false GNOME matches repositories that are not archived and contain the word "GNOME."

good-first-issuesgood-first-issues:>n

good-first-issues:>2 javascript matches repositories with more than two issues labeled good-first-issue and that contain the word "javascript."

 

help-wanted-issueshelp-wanted-issues:>nhelp-wanted-issues:>4 react matches repositories with more than four issues labeled help-wanted and that contain the word "React."

 

 

 

Searching code

QualifierExample
in:fileoctocat in:file matches code where "octocat" appears in the file contents.
in:pathoctocat in:path matches code where "octocat" appears in the file path.
 octocat in:file,path matches code where "octocat" appears in the file contents or the file path.
user: USERNAME user:defunkt extension:rb matches code from @defunkt that ends in .rb .
org: ORGNAME org:github extension:js matches code from GitHub that ends in .js .
repo: USERNAME/REPOSITORY repo:mozilla/shumway extension:as matches code from @mozilla's shumway project that ends in .as .
path:/ octocat filename:readme path:/ matches readme files with the word "octocat" that are located at the root level of a repository.
path: DIRECTORY form path:cgi-bin language:perl matches Perl files with the word "form" in a cgi-bin directory, or in any of its subdirectories.
path: PATH/TO/DIRECTORY console path:app/public language:javascript matches JavaScript files with the word "console" in an app/public directory, or in any of its subdirectories (even if they reside in app/public/js/form-validators ).
language: LANGUAGE element language:xml size:100 matches code with the word "element" that's marked as being XML and has exactly 100 bytes.
 display language:scss matches code with the word "display," that's marked as being SCSS.
 org:mozilla language:markdown matches code from all @mozilla's repositories that's marked as Markdown.
size: n function size:>10000 language:python matches code with the word "function," written in Python, in files that are larger than 10 KB.
filename: FILENAME filename:linguist matches files named "linguist."
 filename:.vimrc commands matches .vimrc files with the word "commands."
 filename:test_helper path:test language:ruby matches Ruby files named test_helper within the test directory.
extension: EXTENSION form path:cgi-bin extension:pm matches code with the word "form," under cgi-bin , with the .pm file extension.
 icon size:>200000 extension:css matches files larger than 200 KB that end in .css and have the word "icon."

Searching users

QualifierExample
type:usermike in:name created:<2011-01-01 type:user matches personal accounts named "mike" that were created before 2011.
type:orgdata in:email type:org matches organizations with the word "data" in their email.
in:loginkenya in:login matches users with the word "kenya" in their username.
in:fullnamebolton in:fullname matches users whose real name contains the word "bolton."
in:emaildata in:email matches users with the word "data" in their email.
repos: n repos:>9000 matches users whose repository count is over 9,000.
 bert repos:10..30 matches users with the word "bert" in their username or real name who own 10 to 30 repositories.
location: LOCATION repos:1 location:iceland matches users with exactly one repository that live in Iceland.
language: LANGUAGE language:javascript location:russia matches users in Russia with a majority of their repositories written in JavaScript.
 jenny language:javascript in:fullname matches users with JavaScript repositories whose full name contains the word "jenny."
created: YYYY-MM-DD created:<2011-01-01 matches users that joined before 2011.
 created:>=2013-05-11 matches users that joined at or after May 11th, 2013.
 created:2013-03-06 location:london matches users that joined on March 6th, 2013, who list their location as London.
 created:2010-01-01..2011-01-01 john in:login matches users that joined between 2010 and 2011 with the word "john" in their username.
followers: n followers:>=1000 matches users with 1,000 or more followers.
 sparkle followers:1..10 matches users with between 1 and 10 followers, with the word "sparkle" in their name.

 

未完待续...

<think> 首先,用户的问题是关于“GitHub搜索技巧”。系统指令要求我使用中文回答,并生成相关问题。回顾引用内容,这些都是关于GitHub搜索技巧的,从如何快速找到资源到高级搜索技巧。 系统指令的关键点: - 所有行内数学表达式必须使用$...$格式。 - 独立公式使用$$...$$格式。 - LaTeX语法正确。 - 使用中文回答。 - 生成相关问题。 - 在回答中引用的段落末尾自然地添加引用标识,如[^1]。 - 回答结构清晰,逐步解决问题,保证真实可靠。 - 参考提供的引用内容,但用户说“上述引用仅供参考”,所以我需要基于这些引用构建回答,但不要直接复制。 用户消息中引用了[1]到[5],内容涵盖: - [^1]: 基本搜索技巧,高级搜索功能,官方帮助指南。 - [^2]: GitHub搜索技巧整理,常用操作,支持各种操作,搜索前登录的建议。 - [^3]: GitHub的好处,快速找到好资源。 - [^4]: 73个GitHub高级搜索技巧,包括排序、搜索范围等。 - [^5]: 具体技巧如高亮显示代码行。 用户明确说:“我想了解GitHub搜索技巧”,所以我需要聚焦在回答这个问题上。 我的回答结构: 1. **介绍GitHub搜索的重要性**:简要提到GitHub作为开发者平台,搜索技巧能帮助高效找到项目、代码等。 2. **核心搜索技巧**:基于引用,分点列出常见和高级技巧。确保使用中文。 - 基本搜索:直接在搜索框中输入关键词。 - 高级搜索:使用限定符。 - 分类搜索:如搜索仓库、代码、用户等。 - 排序和过滤:基于引用[4]。 3. **具体示例**:提供一些例子,比如使用限定符。 4. **引用处理**:在回答中自然地添加引用标识。例如,当提到某个技巧时,加上[^1]或[^2]。 5. **生成相关问题**:在回答末尾添加相关问题。 生成相关问题:指令要求“生成相关问题”。在示例中是“§§相关问题§§”部分。所以我需要在回答最后添加几个相关问题。 确保LaTeX:用户问题中没有数学表达式,所以可能不需要使用LaTeX。但指令说“所有行内数学表达式必须使用$...$格式”,如果涉及数学就用。这里可能不相关,但如果我有公式,就用。否则,忽略。 回答框架: - **引言**:解释GitHub搜索技巧的重要性。 - **主体**: - 基本技巧。 - 高级技巧。 - 使用高级搜索功能。 - **总结**:鼓励实践和使用官方资源。 - **相关问题**:列出3-5个相关问题。 基于引用内容: - 基本搜索:直接输入关键词[^2]。 - 高级限定符:如 `in:name`, `language:`, `stars:` 等[^4]。 - 登录建议:不登录和登录结果不同[^2]。 - 搜索范围:仓库、代码、用户等[^4]。 - 排序:按stars、forks等[^4]。 - 具体技巧:高亮代码行[^5]。 自然添加引用: - 当提到一个技巧时,在句子末尾加上引用标识。 相关问题示例: 1. 如何搜索特定语言的代码? 2. GitHub高级搜索的常见限定符有哪些? 3. 如何在搜索结果中过滤仓库大小? 最终回答用中文。 </think> ### GitHub搜索技巧指南 GitHub是全球最大的代码托管平台,拥有海量开源项目和资源。掌握有效的搜索技巧能帮助您快速找到所需软件、代码库、用户或问题解答,提升开发效率。以下内容基于引用资料整理,我会从基本技巧到高级方法逐步解析,确保实用可靠。 #### 1. **基本搜索技巧** - **直接关键词搜索**:在GitHub主页搜索框中输入关键词(如“python web framework”),系统会自动匹配相关仓库和代码。建议使用简洁、具体的关键词以缩小范围[^2]。 - **登录的重要性**:搜索前务必登录GitHub账号,否则搜索结果可能受限(仅显示部分公共仓库)。登录后,您能访问所有公共仓库的代码,提高搜索覆盖率和准确性[^2]。 - **避免无效搜索**:搜索时避免泛词(如“app”),改用描述性短语。例如,搜索“machine learning library”而非“AI tools”,能获得更精准结果[^3]。 #### 2. **高级搜索限定符** GitHub支持多种限定符(search qualifiers),添加到搜索关键词后可精确过滤结果。所有限定符基于官方文档整理[^4][^1]: - **搜索仓库(Repositories)**: - `in:name`:按仓库名称搜索(如 `in:name python` 搜索名称含“python”的仓库)。 - `stars:>n`:按星标数过滤(如 `stars:>1000` 找热门仓库)。 - `forks:>n`:按分叉数过滤(如 `forks:>500` 找活跃项目)。 - `language:lang`:按编程语言搜索(如 `language:javascript` 搜索JS项目)。 - `created:YYYY-MM-DD`:按创建时间搜索(如 `created:2023-01-01..2023-12-31` 找2023年新仓库)。 - 示例:搜索Python机器学习仓库,可输入 `in:name machine learning language:python stars:>500`[^4]。 - **搜索代码(Code)**: - `in:file`:按文件内容或路径搜索(如 `in:file config.yml` 找含此文件的代码)。 - `path:`:指定文件路径(如 `path:/src/main/java` 搜索Java源码目录)。 - `size:>n`:按文件大小过滤(如 `size:>1000` 找大于1KB的文件)。 - 示例:搜索JavaScript中关于“API调用”的代码片段,输入 `in:file API call language:javascript`[^4]。 - **搜索用户(Users)**: - `user:username`:在特定用户仓库中搜索(如 `user:google tensorflow` 找Google的TensorFlow项目)。 - `followers:>n`:按关注者数过滤(如 `followers:>1000` 找知名开发者)。 - 示例:搜索拥有1000+星标的Python开发者,输入 `language:python followers:>1000`[^4]。 #### 3. **高级搜索功能与应用** - **GitHub高级搜索页面**:如果您觉得手动输入限定符麻烦,访问[GitHub Advanced Search](https://github.com/search/advanced)页面,通过表单自定义条件(如语言、星标数、更新时间),简化操作[^1]。 - **排序搜索结果**:支持按多种标准排序: - `sort:stars` 按星标数降序。 - `sort:forks` 按分叉数排序。 - `sort:updated` 按更新时间排序。 默认搜索按相关性排序,但加上排序限定符能优先显示高质量资源(如 `python sort:stars` 找最受欢迎的Python仓库)[^4]。 - **代码高亮与定位**:在代码文件URL后添加 `#L` 加行号,可直接高亮显示指定行(如 `https://github.com/user/repo/blob/main/file.py#L10-L20` 高亮10-20行代码)。这对于审查或调试代码特别有用[^5]。 - **主题搜索(Topics)**:使用 `topic:keyword` 搜索仓库主题标签(如 `topic:docker` 找Docker相关项目),GitHub主题系统能帮助发现流行工具[^4]。 #### 4. **实用建议与资源** - **组合使用技巧**:例如,搜索一个高星标的Python Web框架,可输入 `in:name web framework language:python stars:>1000`。测试不同组合以优化结果。 - **官方帮助指南**:GitHub提供详细搜索文档[Searching on GitHub](https://help.github.com/en/articles/about-searching-on-github),涵盖项目、代码、评论和问题的搜索方法。定期查阅能掌握最新功能[^1][^2]。 - **性能优化**:保持关键词简洁,避免过多限定符导致结果为空。如果您在找实用资源,优先使用 `stars:>100` 过滤低质量项目[^3]。 - **总结**:GitHub搜索不仅仅是输入关键词——它需要策略性地使用限定符、排序和过滤。通过这些技巧,您能快速定位优质资源,提升开发效率[^3][^4]。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿雷由

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值