GitHub秘籍


本秘籍收录了一些Git和Github非常酷同时又少有人知的功能。灵感来自于Zach Holman在2012年Aloha Ruby Conference和2013年WDCNZ上所做的演讲:Git and GitHub Secrets(slides)和More Git and GitHub Secrets(slides)。

GitHub秘籍 : Git 篇

GitHub 使用教程图文详解 

如何在 GitHub 建立组织

GitHub Linux下使用方法

Windows下Eclipse搭建GitHub开发环境图文教程

Read this in other languages: English, 한국어, 日本語, 简体中文.

忽略空白字符变化

在任意diff页面的URL后加上?w=1,可以去掉那些只是空白字符的变化,使你能更专注于代码的变化。

Diff without whitespace

详见 GitHub secrets.

调整Tab字符所代表的空格数

在diff或者file页面的URL后面加上?ts=4,这样当显示tab字符的长度时就会是4个空格的长度,不再是默认的8个空格。ts后面的数字还可以根据你个人的偏好进行修改。不过,这个小诀窍在Gists页面和raw file页面不起作用。

下面是我们在Go语言的source file页面URL后加?ts=4前的例子:

Before, tab space example

然后是我们添加?ts=4后的例子:

After, tab space example

查看某个用户的Commit历史

查看某个用户的所有提交历史,只需在commits页面URL后加上?author=username。

  1. https://github.com/rails/rails/commits/master?author=dhh

DHH commit history

深入了解提交视图之间的区别

克隆某个仓库

当我们克隆某一资源时,可以不要那个.git后缀。

  1. $ git clone https://github.com/tiimgreen/github-cheat-sheet

更多对 Git clone 命令的介绍.

将某个分支与其他所有分支进行对比

当你点击某个仓库的分支(Branches)选项卡时

  1. https://github.com/{user}/{repo}/branches

你会看到一个包含所有未合并的分支的列表。

你可以在这里查看比较(Compare)页面或点击删除某个分支。

Compare branches not merged into master in jquery/jquery repo - https://github.com/jquery/jquery/branches

有的时候我们需要将多个分支与一个非主分支(master)进行对比,此时可以通过在URL后加入要比较的分支名来实现:

  1. https://github.com/{user}/{repo}/branches/{branch}

Compare branches not merged into `1.x-master` in jquery/jquery repo - https://github.com/jquery/jquery/branches/1.x-master

可以在URL后加上?merged=1来查看已经合并了的分支。

Compare branches merged in to `1.x-master` in jquery/jquery repo - https://github.com/jquery/jquery/branches/1.x-master?merged=1

你可以使用这个界面来替代命令行直接删除分支。

比较分支

如果我们想要比较两个分支,可以像下面一样修改URL:

  1. https://github.com/user/repo/compare/{range}

其中{range} = master...4-1-stable

例如:

  1. https://github.com/rails/rails/compare/master...4-1-stable

Rails branch compare example

{range}还可以使用下面的形式:

  1. https://github.com/rails/rails/compare/master@{1.day.ago}...master
  2. https://github.com/rails/rails/compare/master@{2014-10-04}...master

日期格式 YYYY-DD-MM

Another compare example

...这样你就能查看master分支上一段时间或者指定日期内的改动。

了解更多关于比较跨时间段的提交记录.

比较不同派生库的分支

想要对派生仓库(Forked Repository)之间的分支进行比较,可以像下面这样修改URL实现:

  1. https://github.com/user/repo/compare/{foreign-user}:{branch}...{own-branch}

例如:

  1. https://github.com/rails/rails/compare/byroot:master...master

Forked branch compare

Gists

Gists 给我们提供了一种不需要创建一个完整的仓库,使小段代码也可以工作的简单方式。

Gist

Gist的URL后加上.pibb,可以得到更适合嵌入到其他网站的HTML版本。

Gists还可以像任何标准仓库一样被克隆。

  1. $ git clone https://gist.github.com/tiimgreen/10545817

Gists

进一步了解如何创建 gists.

Git.io

Git.io是Github的短网址服务。

Git.io

你可以通过Curl命令以普通HTTP协议使用它:

  1. $ curl -i http://git.io -F "url=https://github.com/..."
  2. HTTP/1.1201Created
  3. Location: http://git.io/abc123
  4.  
  5. $ curl -i http://git.io/abc123
  6. HTTP/1.1302Found
  7. Location: https://github.com/...

进一步了解 Git.io.

键盘快捷键

在仓库主页上提供了快捷键方便快速导航。

  • 按 t 键会打开一个文件浏览器。
  • 按 w 键会打开分支选择菜单。
  • 按 s 键会激活顶端的命令栏 (Command Bar)。
  • 按 l 键编辑Issue列表页的标签。
  • 查看文件内容时(如:https://github.com/tiimgreen/github-cheat-sheet/blob/master/README.md),按 y 键将会冻结这个页面,这样就算代码被修改了也不会影响你当前看到的。

按?查看当前页面支持的快捷键列表:

Keyboard shortcuts

进一步了解如何使用 Command Bar.

整行高亮

在代码文件地址后加上#L52或者单击行号52都会将第52行代码高亮显示。

多行高亮也可以,比如用#L53-L60选择范围,或者按住 shift键,然后再点击选择的两行。

  1. https://github.com/rails/rails/blob/master/activemodel/lib/active_model.rb#L53-L60

整行高亮

更多详情见请继续阅读下一页的精彩内容:

  • 1
  • 2
  • 3
  • 下一页

相关内容