GitHub 搜索技巧指南 Shepard-Wang

一 搜索技巧

1、根据star,fork数筛选

1, 大于等于


  语法: 关键字 stars:>= 数量 forks:>=数量 
  例子: springboot stars:>=5000 //搜索springboot有关star数>=5000的内容
        springboot stars:>=5000 forks:>=5000//搜索springboot 的star>=5000,且fork数>=5000的内容
    可单独搜索,也可组合搜索,中间用空格隔开,是&(且)的关系。

2,范围查询


  语法: 关键字 stars:范围1..范围2
  例子: springboot stars:4000..5000 
    //搜索star数在 4000到500的springboot相关内容,..相当于mysql中between and 的作用。

2、 关键字 in

搜索关键字在github上发布的位置 ,主要以下3个位置

  • name (发布的仓库名称)
  • description(指的是仓库的 description
  • Readme (说明文档)
语法 :关键字 in:
例子 :netty in:name //查找名称中包含netty的内容
      netty in:name,description
      //逗号分隔,是 || (或)的关系,指的是查询名称,或者描述中包含netty的内容

3、awesome + 关键字

一般是指的学习,书籍,工具类,插件类相关的系列的集合。可以有效节约时间,找到别人收集好的内容。

awesome 指的是了不起的,碉堡了。

github 官方解释:
An awesome list is a list of awesome things curated by the community.
大致意思:社区组织维护的一系列非常棒的东西的集合。(差不多吧,哈哈,水平有限,谷歌翻译了解一下)

4、搜索某个语言,某个地区的大佬

例如: location:Beijing language:java 

5、 实现某行,某块代码高亮

在与其他人协作开发时,沟通时在给别人指出某行,或者某块代码,可以在github链接后面加上

1,#L23  //某行高亮
如:
https://github.com/unofficial-openjdk/openjdk/blob/jdk/jdk/test/jdk/sun/misc/GetSunMiscUnsafe.java#L36

如图7所示 img

2,#L23-35  //某个代码块
如:
https://github.com/unofficial-openjdk/openjdk/blob/jdk/jdk/test/jdk/sun/misc/GetSunMiscUnsafe.java#L36-L40

如图8所示 img

6、user

查询某位用户的相关内容,比如某位大佬

语法:user:名称

例子:user:ityouknow

二 进阶技巧

Scope the search fields

指定搜索方式

octocat in:file

Matches code where “octocat” appears in the file contents.

搜索文件中有octocat的代码

octocat in:path

Matches code where “octocat” appears in the path name.

搜索路径中有octocat的代码

octocat in:file,path

Matches code where “octocat” appears in the file contents or the path name.

搜索路径中有octocat的代码或者文件中有octocat的代码

display language:scss

Matches code with the word “display,” that’s marked as being SCSS.

搜索用scss写的包含display的代码

Integer

Matches code with the word “Integer”.

搜索包含Integer的字段

Search by language

通过语言搜索代码

You can search for code based on what language it’s written in. For example:

element language:xml size:100

Matches code with the word “element” that’s marked as being XML and has exactly 100 bytes.

搜索大小为100字节的xml代码

user:mozilla language:markdown

Matches code from all @mozilla’s repositories that’s marked as Markdown.

搜索mozilla用户下用markdown写的代码

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:

android language:java fork:true

Matches code in a forked repository with the word “android” that’s written in Java.

搜索用java写的 android相关的代码并且被fork过

###

The size qualifier filters results based on the size of the file in which the code is found. For example:

function size:>10000 language:python

Matches code with the word “function,” written in Python, in files that are larger than 10 KB.

搜索与function相关的python代码,文件大小超过10kb

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:

console path:app/public language:javascript

Finds JavaScript files with the word “console” in an app/public directory (even if they reside in app/public/js/form-validators).

app/public directory目录下搜索console关键字

form path:cgi-bin language:perl

Finds Perl files under cgi-bin with the word “form” in them.

搜索cgi-bin目录下包含form的perl代码

Search by filename

通过文件名搜索

You can use the filename qualifier if there’s a specific file you’re looking for. For example:

filename:.vimrc commands

Finds .vimrc files with the word “commands” in them.

搜索 文件名匹配.vimrc 并且包含commands的代码

minitest filename:test_helper path:test language:ruby

Finds Ruby files containing the word “minitest” named test_helper within the test directory.

在test目录中搜索包含minitest且文件名匹配”test_helper“的代码

Search by the file extension

根据扩展名来搜索代码

The extension qualifier matches code files with a certain extension. For example:

form path:cgi-bin extension:pm

Matches code with the word “form,” under cgi-bin, with the .pm extension.

搜索cgi-bin目录下以pm为扩展名的代码

icon size:>200000 extension:css

Finds files larger than 200 KB that end in .css and have the word “icon” in them.

搜索超过200kb包含icon的css代码

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:

user:github extension:rb

Matches code from GitHub that ends in .rb.

查找github用户中以rb为扩展的代码

repo:mozilla/shumway extension:as

Matches code from @mozilla’s shumway project that ends in .as.

搜索mozilla的shumway以as为扩展的代码

参考资料:

  1. https://www.iteye.com/blog/robbiefeng-2169967
  2. https://www.cnblogs.com/flydashpig/p/11795238.html