GitHub项目代码搜索使用等技巧
GitHub项目、代码搜索、使用等技巧
github作为全球最大的代码托管网站,受到世界上广大码农的追捧。在这里你可以发现很多很棒的开源项目,也可以构建免费的私人仓库,简直就是一个学习成长的乐园。下面就一些常见的github操作进行如下总结:
一、github初了解
github将所有的改动行为称为contributions,包括commit,pr, code review,isssue,fork等等。github有个叫活动概览(Activity overview)的功能,将contributions按照下面四个象限进行分类统计:
- Commits: 建仓、提交代码或fork等会触发
- Pull requests: 指开发者在本地对源代码进行更改后,向 GitHub 中托管的 Git 仓库请求合并的功能。
- Code review :预览代码
- Issues: 用于 BUG 报告、功能添加、方向性讨论等,将这些以 Issue 形式进行管理。
二、Github使用技巧:
很多人搜索github,但是芸芸众生,要找到自己想要的项目犹如海底捞针一般,今天教大家几项神技,可以快速找到自己想要的内容。
1、按star数目搜索,比如 ,要求星数,这样就能获取star数目最多的项目
2、follow一些github上面的大牛
请登录:https://github-ranking.com/
国内大牛:http://outofmemory.cn/github/
这里是搜索名人的网址:https://github.com/search
高级搜索:https://github.com/search/advanced
3、Awesome + 你的关键字:搜索一些优秀的框架、教程、项目等
4、看一些搜索技巧,设定条件进行搜索
地址:https://help.github.com/articles/searching-repositories/
5、通过readme看看人家是否发出pull request
看看这篇文章:http://blog.csdn.net/qianlong4526888/article/details/11529981
6、看explore推荐
7、看看其他
8、直接github上搜fackbook或者其他,可以看到他们的最新作品
github是一个非常丰富的资源,但是面对这丰富的资源很多人不知到怎么使用,更谈不上怎么贡献给他,我们需要使用github就要学习使用他的方法,学会了使用的方法,接受了他的这种观点我们才会慢慢的给他贡献自己的力量,这是我自己在学习的时候的一个笔记。现在分享给大家希望能够对一些人有帮助。
三、github搜索之代码搜索 ( / Searching code )
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 is not valid, while 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的代码才是可以搜索到的
搜索的时候必须包含至少一个搜索关键词
搜索语句不能有特殊字符如
., : ; / \
’ " = * ! ? # $ & + ^ | ~ < > ( ) { } []`
.
Scope the search fields
指定搜索方式
- 搜索文件中有octocat的代码—- ( Matches code where “octocat” appears in the file contents. )
- 搜索路径中有octocat的代码— ( Matches code where “octocat” appears in the path name. )
- 搜索路径中有octocat的代码或者文件中有octocat的代码— ( Matches code where “octocat” appears in the file contents or the path name. )
- 搜索用scss写的包含display的代码— ( Matches code with the word “display,” that’s marked as being SCSS. )
- 搜索包含Integer的字段— ( Matches code with the word “Integer”. )
Search by language
通过语言搜索代码
- 搜索大小为100字节的xml代码– ( Matches code with the word “element” that’s marked as being XML and has exactly 100 bytes. )
- 搜索mozilla用户下用markdown写的代码– ( Matches code from all @mozilla’s repositories that’s marked as Markdown. )
Search by the number of forks the parent repository has
通过fork的数量或者是否有父节点的方式搜索
- 搜索用java写的 android相关的代码并且被fork过– ( Matches code in a forked repository with the word “android” that’s written in Java. )
- 搜索与function相关的python代码,文件大小超过10kb– ( Matches code with the word “function,” written in Python, in files that are larger than 10 KB. )
Search by the location of a file within the repository
按照目录结构搜索
- 在app/public directory目录下搜索console关键字 – ( Finds JavaScript files with the word “console” in an app/public directory (even if they reside inapp/public/js/form-validators). )
- 搜索cgi-bin目录下包含form的perl代码– ( Finds Perl files under cgi-bin with the word “form” in them. )
Search by filename
通过文件名搜索
- 搜索 文件名匹配*.vimrc* 并且包含commands的代码– ( Finds .vimrc files with the word “commands” in them. )
- 在test目录中搜索包含minitest且文件名匹配"test_helper“的代码– ( Finds Ruby files containing the word “minitest” named test_helper within the test directory. )
Search by the file extension
根据扩展名来搜索代码
- 搜索cgi-bin目录下以pm为扩展名的代码– ( Matches code with the word “form,” under cgi-bin, with the .pm extension. )
- 搜索超过200kb包含icon的css代码– ( Finds files larger than 200 KB that end in .css and have the word “icon” in them. )
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:
四、推荐项目:
这个项目目前 star 数排名 GitHub 第三,总 star 数超过6w,这个项目整理了所有跟编程相关的免费书籍,而且全球多国语言版的都有,中文版的在这里: ,有了这个项目,理论上你可以获取任何编程相关的学习资料,强烈推荐给你们!
俗话说,不会用 shell 的程序员不是真正的程序员,所以建议每个程序员都懂点 shell,有用不说,装逼利器啊!而 oh-my-zsh 毫无疑问就是目前最流行,最酷炫的 shell,不多说了,懂得自然懂,不懂的以后你们会懂的!
GitHub 上有各种 awesome 系列,简单来说就是这个系列搜罗整理了 GitHub 上各领域的资源大汇总,比如有 awesome-android, awesome-ios, awesome-java, awesome- 等等。
GitHub 的使用有各种技巧,只不过基本的就够我们用了,但是如果你对 GitHub 超级感兴趣,想更多的了解 GitHub 的使用技巧,那么这个项目就刚好是你需要的,每个 GitHub 粉都应该知道这个项目。
五、加载慢,访问不了
针对Windows下访问GitHub慢,有些图片加载不全的情况,进行如下处理
(1)查看IP:打开 ,分别查github.com、github.githubassets.com、avatars0.githubusercontent.com
(2)修改hosts文件
利用记事本或者notepad++打开C:\Windows\System32\drivers\etc\hosts(修改前可以先另存为一份,保证出错能恢复),然后添加以下内容
# GitHub Start
192.30.253.113 github.com
185.199.109.154 github.githubassets.com
185.199.111.154 github.githubassets.com
203.98.7.65 gist.github.com
151.101.108.133 assets-cdn.github.com
151.101.108.133 raw.githubusercontent.com
151.101.108.133 gist.githubusercontent.com
151.101.108.133 cloud.githubusercontent.com
151.101.108.133 camo.githubusercontent.com
151.101.108.133 avatars0.githubusercontent.com
151.101.108.133 avatars1.githubusercontent.com
151.101.108.133 avatars2.githubusercontent.com
151.101.108.133 avatars3.githubusercontent.com
151.101.108.133 avatars4.githubusercontent.com
151.101.108.133 avatars5.githubusercontent.com
151.101.108.133 avatars6.githubusercontent.com
151.101.108.133 avatars7.githubusercontent.com
151.101.108.133 avatars8.githubusercontent.com
# GitHub End
(3)刷新DNS
在cmd中输入
ipconfig /flushdns
即可刷新,然后重启浏览器,不行的话再重启电脑,这样就能成功打开github了,所有图片和内容都能加载。
在gitee上有大佬总结了访问策略,具体可查看链接:
https://gitee.com/docmirror/dev-sidecar
六、加速下载
有时候需要在GitHub下载一些开源项目,但是直接下网速慢到爆炸,这时候需要借助一些手段对其进行下载加速,常见的有 :
- (需注册),这是一个仿github的代码托管平台,通过导入目标开源项目,然后在下载。
另一个平台: ,无需注册,直接拷贝目标项目链接就可以快速下载。(已失效)
- Github 加速下载:
将github上项目链接复制到输入框中就可以代理加速下载!
- 打开网站 ,粘贴链接直接下载,或者直接在后台使用下面加速指令
git clone https://ghproxy.com/https://github.com/stilleshan/ServerStatus ###下载链接前添加https://ghproxy.com即可
git clone git://ghproxy.com/https://github.com/stilleshan/ServerStatus ###加速方法二
git clone https://github.com.cnpmjs.org/stilleshan/ServerStatus ###加速方法三
git clone https://hub.fastgit.org/stilleshan/ServerStatus ###加速方法四
git clone https://github.91chi.fun//https://github.com/stilleshan/ServerStatus ###加速方法五
但是 上面几种方法都没办法解决从github上下载一些release的打包文件,故有大佬又针对性的开发了新的加速方法,
- 可以拷贝下载链接通过
下载,但是需要先注册,速度还可以。
- 这个网站 ,可以直接使用,不要注册,大家直接copy链接上手
七、针对下载
》有时候我们会碰到下载指定分支的github开源项目(默认git clone的是最新的),这时候就可以借助下面指令实现
git clone -b application https://hub.fastgit.org/PaddlePaddle/PaddleVideo.git ##b后接上分支名
》如果下载 Github 上某些代码仓库时,如果代码仓库中具有很多子模块,正常使用
git clone —-recursive
下载方式,
git clone --recursive https://github.com/onnx/onnx-mlir.git
八、查看代码
对于github上面的项目代码,除了download到本地进行查看,还可以轻松实现在线代码阅读,常见的方法如下,
(1)直接将代码链接中的github.com换成github1s.com即可。
(2)安装octree或者sourcegraph插件实现code在线浏览
哈哈哈,就先写到这,有兴趣的可以关注我的公众号,大家一起学习啦!
补充:代码搜索网站:
代码:
可以搜索特殊符号的搜索引擎,程序员的福音,遇到 Bash、正则之类的问题时候的利器!
Haskell 的专用函数搜索引擎,妈妈再也不用担心我的 Functional Programming
R 语言专用搜索。
JAR 搜索引擎,对 Java 编程有帮助。
微软内部搜索,好东西多多,经常会发现 Google 学术搜不到的技术文献
针对 SEO 排名的知识搜索引擎: ,完全在线学习 + 公式化结构化的 SEO 搜索算法
从世界各地查询网站的 Ping 结果。
补:
知道如何下载github指定版本的开源项目么,那么你可能会用到下面指令,以yolov5为例
git clone -b v4.0 https://github.com/ultralytics/yolov5.git
git clone -b yolov5-v4.0 https://github.com/wang-xinyu/tensorrtx.git
参考链接:
(如何发现优秀的开源项目)