少有人知的 GitHub 使用技巧

GitHub 你們常上吧?但是使用 GitHub 的各類小竅門你就不必定知道了。本文將各類使用 GitHub 的小竅門分享給你們。git

diff時忽略空格

有些修改只是增減了空格,在URL中添加?w=1就能夠忽略。github

查看某個做者的提交歷史

在URL中添加?author=username,例如:segmentfault

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

比較版本

使用相似以下的URL比較分支:curl

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

一樣可使用一下格式:網站

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

若是想和派生倉庫比較,加上派生倉庫名做前綴便可:ui

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

經過 HTML 方式嵌入 Gist

Gists是 GitHub 推出的基於 Git 的代碼片斷服務。Gists頁面提供JavaScript代碼,能夠將 Gist 嵌入到其餘站點。可是不少站點粘貼 JavaScript 無效,這時候你能夠在 Gist URL 後附加.pibb,獲得一個純 HTML 的版本,而後就能夠複製粘貼 HTML 源碼到其餘網站了。例如 https://gist.github.com/tiimgreen/10545817.pibburl

Git.io

Git.io 是適用於 GitHub 的短網址服務。spa

固然,爲了逼格方便,也可使用Curl訪問:code

$ curl -i http://git.io -F "url=https://github.com/..."
HTTP/1.1 201 Created
Location: http://git.io/abc123

$ curl -i http://git.io/abc123
HTTP/1.1 302 Found
Location: https://github.com/...

你甚至能夠指定短網址的字段:ip

$ curl -i http://git.io -F "url=https://github.com/technoweenie" \
    -F "code=t"
HTTP/1.1 201 Created
Location: http://git.io/t

高亮行

例如,在 URL 中加上 #L52 能夠高亮第52行。或者你也能夠直接點擊行數。

多行高亮一樣支持。你可使用相似#L53-L60格式,或者在按住shift的同時點擊。

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

快速引用

你能夠選中別人的評論文字,而後按r,這些內容會以引用的形式被複制在文本框中:

任務列表

在工單或合併請求中,你可使用任務列表語法:

- [ ] Be awesome
- [ ] Do stuff
- [ ] Sleep

勾選以後,會更新 Markdown:

- [x] Be awesome
- [x] Do stuff
- [ ] Sleep

合併請求的 diff 和 patch

能夠在 URL 後添加 .diff.patch,以對應的模式查看合併請求:

https://github.com/tiimgreen/github-cheat-sheet/pull/15
https://github.com/tiimgreen/github-cheat-sheet/pull/15.diff
https://github.com/tiimgreen/github-cheat-sheet/pull/15.patch

結果是純文本的:

diff --git a/README.md b/README.md
index 88fcf69..8614873 100644
--- a/README.md)
+++ b/README.md
@@ -28,6 +28,7 @@ All the hidden and not hidden features of Git and GitHub. This cheat sheet was i
 - [Merged Branches](#merged-branches)
 - [Quick Licensing](#quick-licensing)
 - [TODO Lists](#todo-lists)
+- [Relative Links](#relative-links)
 - [.gitconfig Recommendations](#gitconfig-recommendations)
     - [Aliases](#aliases)
     - [Auto-correct](#auto-correct)
@@ -381,6 +382,19 @@ When they are clicked, they will be updated in the pure Markdown:
 - [ ] Sleep

(...)

編撰 SegmentFault
參考 github-cheat-sheet

相關文章
相關標籤/搜索