├── .github └── FUNDING.yml ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.ja.md ├── README.ko.md ├── README.md ├── README.zh-cn.md └── README.zh-tw.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [tiimgreen] 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | 3 | rvm: 4 | - 2.2 5 | 6 | before_script: 7 | - gem install awesome_bot 8 | 9 | script: 10 | - wl=https://github.com/rails/rails/compare/master@,http://git.io/abc123,https://github.com/..,youtube,chrome.google.com/webstore,https://github.com/mathiasbynens/dotfiles/blob/master/.gitconfig*,https://github.com/user/repo/compare/,vimeo 11 | - awesome_bot README.md --allow-dupe --allow-redirect --white-list $wl 12 | - awesome_bot README.ko.md --allow-dupe --allow-redirect --white-list $wl 13 | - awesome_bot README.ja.md --allow-dupe --allow-redirect --white-list $wl 14 | - awesome_bot README.zh-cn.md --allow-dupe --allow-redirect --white-list $wl 15 | - awesome_bot README.zh-tw.md --allow-dupe --allow-redirect --white-list $wl 16 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | 1. Fork the repository. 4 | 2. Add your section - make sure you follow the styling guide below. 5 | 3. Commit changes. 6 | 4. Push your commit. 7 | 5. Create a Pull Request. 8 | 9 | ## Styling 10 | 11 | - Use `###` headers for your sections. 12 | - Also use `###` for categories (these should group together relevant sections) and `####` for subcategories. 13 | - Add a link to your section/category to the contents section (use relative links). 14 | - Make sure to include examples wherever possible (preferably GIFs). 15 | - For command-line examples, wrap your commands in a `bash` code block. 16 | - At the end of your section, add a `Read more about...` link. This should directly link to [Git's](http://git-scm.com/docs), [GitHub's](https://help.github.com), or the relevant documentation. 17 | - If your contribution is a translation, add a (relative) link to the README above the [Table of Contents](README.md#table-of-contents). 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Tim Green 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.ja.md: -------------------------------------------------------------------------------- 1 | # GitHubカンニング・ペーパー [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 2 | これはGitやGitHubの隠された機能やよく知られていない機能の一覧だ。[Zach Holman](https://github.com/holman)によるAloha Ruby Conference 2012での[Git and GitHub Secrets](https://github.com/tiimgreen/github-cheat-sheet)([スライド](https://github.com/tiimgreen/github-cheat-sheet))とWDCNZ 2013での[More Git and GitHub Secrets](https://vimeo.com/72955426)([スライド](https://speakerdeck.com/holman/more-git-and-github-secrets))の二つのトークを元にしている。 3 | 4 | *短縮URL: [`http://git.io/sheet`](http://git.io/sheet)* 5 | 6 | *Read this in other languages: [English](README.md), [한국어](README.ko.md), [日本語](README.ja.md), [简体中文](README.zh-cn.md), [正體中文](README.zh-tw.md).* 7 | 8 | # 目次 9 | - [GitHub](#github) 10 | - [空白の無視](#%E7%A9%BA%E7%99%BD%E3%81%AE%E7%84%A1%E8%A6%96) 11 | - [タブ幅の調節](#%E3%82%BF%E3%83%96%E5%B9%85%E3%81%AE%E8%AA%BF%E7%AF%80) 12 | - [特定のユーザーによるコミット履歴](#%E7%89%B9%E5%AE%9A%E3%81%AE%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E3%81%AB%E3%82%88%E3%82%8B%E3%82%B3%E3%83%9F%E3%83%83%E3%83%88%E5%B1%A5%E6%AD%B4) 13 | - [リポジトリのクローン](#%E3%83%AA%E3%83%9D%E3%82%B8%E3%83%88%E3%83%AA%E3%81%AE%E3%82%AF%E3%83%AD%E3%83%BC%E3%83%B3) 14 | - [ブランチ](#%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81) 15 | - [全ブランチを別のブランチと比較](#%E5%85%A8%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81%E3%82%92%E5%88%A5%E3%81%AE%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81%E3%81%A8%E6%AF%94%E8%BC%83) 16 | - [ブランチ同士の比較](#%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81%E5%90%8C%E5%A3%AB%E3%81%AE%E6%AF%94%E8%BC%83) 17 | - [フォークされたリポジトリ間でのブランチ比較](#%E3%83%95%E3%82%A9%E3%83%BC%E3%82%AF%E3%81%95%E3%82%8C%E3%81%9F%E3%83%AA%E3%83%9D%E3%82%B8%E3%83%88%E3%83%AA%E9%96%93%E3%81%A7%E3%81%AE%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81%E6%AF%94%E8%BC%83) 18 | - [Gists](#gists) 19 | - [Git.io](#gitio) 20 | - [キーボード・ショートカット](#%E3%82%AD%E3%83%BC%E3%83%9C%E3%83%BC%E3%83%89%E3%82%B7%E3%83%A7%E3%83%BC%E3%83%88%E3%82%AB%E3%83%83%E3%83%88) 21 | - [コードの指定行の強調](#%E3%82%B3%E3%83%BC%E3%83%89%E3%81%AE%E6%8C%87%E5%AE%9A%E8%A1%8C%E3%81%AE%E5%BC%B7%E8%AA%BF) 22 | - [コミットからissueを閉じる](#%E3%82%B3%E3%83%9F%E3%83%83%E3%83%88%E3%81%8B%E3%82%89issue%E3%82%92%E9%96%89%E3%81%98%E3%82%8B) 23 | - [issueの相互リンク](#issue%E3%81%AE%E7%9B%B8%E4%BA%92%E3%83%AA%E3%83%B3%E3%82%AF) 24 | - [コメントのロック](#%E3%82%B3%E3%83%A1%E3%83%B3%E3%83%88%E3%81%AE%E3%83%AD%E3%83%83%E3%82%AF) 25 | - [pull requestでのCI結果の表示](#pull-request%E3%81%A7%E3%81%AEci%E7%B5%90%E6%9E%9C%E3%81%AE%E8%A1%A8%E7%A4%BA) 26 | - [絞り込み検索](#%E7%B5%9E%E3%82%8A%E8%BE%BC%E3%81%BF%E6%A4%9C%E7%B4%A2) 27 | - [Markdownファイルでの構文強調](#markdown%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%A7%E3%81%AE%E6%A7%8B%E6%96%87%E5%BC%B7%E8%AA%BF) 28 | - [Emoji](#emoji) 29 | - [画像及びアニメーションGIF](#%E7%94%BB%E5%83%8F%E5%8F%8A%E3%81%B3%E3%82%A2%E3%83%8B%E3%83%A1%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3gif) 30 | - [GitHub Wikiへの画像の添付](#github-wiki%E3%81%B8%E3%81%AE%E7%94%BB%E5%83%8F%E3%81%AE%E6%B7%BB%E4%BB%98) 31 | - [素早く引用](#%E7%B4%A0%E6%97%A9%E3%81%8F%E5%BC%95%E7%94%A8) 32 | - [コメントへのクリップボードの画像の追加](#%E3%82%B3%E3%83%A1%E3%83%B3%E3%83%88%E3%81%B8%E3%81%AE%E3%82%AF%E3%83%AA%E3%83%83%E3%83%97%E3%83%9C%E3%83%BC%E3%83%89%E3%81%AE%E7%94%BB%E5%83%8F%E3%81%AE%E8%BF%BD%E5%8A%A0) 33 | - [設定済みライセンスの追加](#%E8%A8%AD%E5%AE%9A%E6%B8%88%E3%81%BF%E3%83%A9%E3%82%A4%E3%82%BB%E3%83%B3%E3%82%B9%E3%81%AE%E8%BF%BD%E5%8A%A0) 34 | - [タスクリスト](#%E3%82%BF%E3%82%B9%E3%82%AF%E3%83%AA%E3%82%B9%E3%83%88) 35 | - [Markdownファイルでのタスクリスト](#markdown%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%A7%E3%81%AE%E3%82%BF%E3%82%B9%E3%82%AF%E3%83%AA%E3%82%B9%E3%83%88) 36 | - [相対リンク](#%E7%9B%B8%E5%AF%BE%E3%83%AA%E3%83%B3%E3%82%AF) 37 | - [GitHub Pagesでのメタデータとプラグインのサポート](#github-pages%E3%81%A7%E3%81%AE%E3%83%A1%E3%82%BF%E3%83%87%E3%83%BC%E3%82%BF%E3%81%A8%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E3%81%AE%E3%82%B5%E3%83%9D%E3%83%BC%E3%83%88) 38 | - [文書内のYAMLメタデータ](#%E6%96%87%E6%9B%B8%E5%86%85%E3%81%AEyaml%E3%83%A1%E3%82%BF%E3%83%87%E3%83%BC%E3%82%BF) 39 | - [表形式のデータ表示](#%E8%A1%A8%E5%BD%A2%E5%BC%8F%E3%81%AE%E3%83%87%E3%83%BC%E3%82%BF%E8%A1%A8%E7%A4%BA) 40 | - [PDF表示](#pdf%E8%A1%A8%E7%A4%BA) 41 | - [pull requestの取り消し](#pull-request%E3%81%AE%E5%8F%96%E3%82%8A%E6%B6%88%E3%81%97) 42 | - [差分の表示](#%E5%B7%AE%E5%88%86%E3%81%AE%E8%A1%A8%E7%A4%BA) 43 | - [レンダリング済みの差分表示](#%E3%83%AC%E3%83%B3%E3%83%80%E3%83%AA%E3%83%B3%E3%82%B0%E6%B8%88%E3%81%BF%E3%81%AE%E5%B7%AE%E5%88%86%E8%A1%A8%E7%A4%BA) 44 | - [マップ差分の可視化](#%E3%83%9E%E3%83%83%E3%83%97%E5%B7%AE%E5%88%86%E3%81%AE%E5%8F%AF%E8%A6%96%E5%8C%96) 45 | - [差分表示の前後を表示](#%E5%B7%AE%E5%88%86%E8%A1%A8%E7%A4%BA%E3%81%AE%E5%89%8D%E5%BE%8C%E3%82%92%E8%A1%A8%E7%A4%BA) 46 | - [pull requestの内容をDIFFまたはPATCH形式で取得](#pull-request%E3%81%AE%E5%86%85%E5%AE%B9%E3%82%92diff%E3%81%BE%E3%81%9F%E3%81%AFpatch%E5%BD%A2%E5%BC%8F%E3%81%A7%E5%8F%96%E5%BE%97) 47 | - [画像の表示とDIFF](#%E7%94%BB%E5%83%8F%E3%81%AE%E8%A1%A8%E7%A4%BA%E3%81%A8diff) 48 | - [Hub](#hub) 49 | - [開発参加のガイドライン](#%E9%96%8B%E7%99%BA%E5%8F%82%E5%8A%A0%E3%81%AE%E3%82%AC%E3%82%A4%E3%83%89%E3%83%A9%E3%82%A4%E3%83%B3) 50 | - [Octicons](#octicons) 51 | - [GitHub情報](#github%E6%83%85%E5%A0%B1) 52 | - [GitHub Talks](#github-talks) 53 | - [Git](#git) 54 | - [すべての削除済みファイルをワーキング・ツリーから削除する](#%E3%81%99%E3%81%B9%E3%81%A6%E3%81%AE%E5%89%8A%E9%99%A4%E6%B8%88%E3%81%BF%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92%E3%83%AF%E3%83%BC%E3%82%AD%E3%83%B3%E3%82%B0%E3%83%84%E3%83%AA%E3%83%BC%E3%81%8B%E3%82%89%E5%89%8A%E9%99%A4%E3%81%99%E3%82%8B) 55 | - [直前のブランチ](#%E7%9B%B4%E5%89%8D%E3%81%AE%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81) 56 | - [空白の削除](#%E7%A9%BA%E7%99%BD%E3%81%AE%E5%89%8A%E9%99%A4) 57 | - [SSH公開鍵](#ssh%E5%85%AC%E9%96%8B%E9%8D%B5) 58 | - [pull requestのチェックアウト](#pull-request%E3%81%AE%E3%83%81%E3%82%A7%E3%83%83%E3%82%AF%E3%82%A2%E3%82%A6%E3%83%88) 59 | - [空のコミット](#%E7%A9%BA%E3%81%AE%E3%82%B3%E3%83%9F%E3%83%83%E3%83%88) 60 | - [Gitステータスのスタイリング](#git%E3%82%B9%E3%83%86%E3%83%BC%E3%82%BF%E3%82%B9%E3%81%AE%E3%82%B9%E3%82%BF%E3%82%A4%E3%83%AA%E3%83%B3%E3%82%B0) 61 | - [Gitログのスタイリング](#git%E3%83%AD%E3%82%B0%E3%81%AE%E3%82%B9%E3%82%BF%E3%82%A4%E3%83%AA%E3%83%B3%E3%82%B0) 62 | - [コミットログの検索](#%E3%82%B3%E3%83%9F%E3%83%83%E3%83%88%E3%83%AD%E3%82%B0%E3%81%AE%E6%A4%9C%E7%B4%A2) 63 | - [Git Grep](#git-grep) 64 | - [マージ済みブランチ](#%E3%83%9E%E3%83%BC%E3%82%B8%E6%B8%88%E3%81%BF%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81) 65 | - [FixupとAutosquash](#fixup%E3%81%A8autosquash) 66 | - [ローカル・リポジトリを参照するウェブサーバー](#%E3%83%AD%E3%83%BC%E3%82%AB%E3%83%AB%E3%83%AA%E3%83%9D%E3%82%B8%E3%83%88%E3%83%AA%E3%82%92%E5%8F%82%E7%85%A7%E3%81%99%E3%82%8B%E3%82%A6%E3%82%A7%E3%83%96%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC) 67 | - [Gitの設定](#git%E3%81%AE%E8%A8%AD%E5%AE%9A) 68 | - [エイリアス](#%E3%82%A8%E3%82%A4%E3%83%AA%E3%82%A2%E3%82%B9) 69 | - [コマンドの自動修正](#%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%AE%E8%87%AA%E5%8B%95%E4%BF%AE%E6%AD%A3) 70 | - [色設定](#%E8%89%B2%E8%A8%AD%E5%AE%9A) 71 | - [Git情報](#git%E6%83%85%E5%A0%B1) 72 | - [Git Books](#git-books) 73 | - [訳注](#%E8%A8%B3%E6%B3%A8) 74 | 75 | ## GitHub 76 | ### 空白の無視 77 | GitHub上で差分ページを表示している時、そのURLに`?w=1`を加えると、空白の変化によるできた差分は表示されなくなり、コード上の変化だけを参照することができる。 78 | 79 | ![Diff without whitespace](https://camo.githubusercontent.com/797184940defadec00393e6559b835358a863eeb/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f776869746573706163652e706e67) 80 | 81 | [*GitHubの秘密についてもっと詳しく*](https://github.com/blog/967-github-secrets) 82 | 83 | ### タブ幅の調節 84 | 差分やファイルを表示している時、URLに`?ts=4`を追加するとタブを空白4つの幅で表示する。デフォルトは8つだ。`ts`に指定した数で表示されるということだ。これはGistやrawファイルを表示している時には適用されないが、[Chrome](https://chrome.google.com/webstore/detail/github-tab-size/ofjbgncegkdemndciafljngjbdpfmbkn)をインストールすることにより、対応することができる。 85 | 86 | 例えばGoのソースファイルを表示している時、`?ts=4`を追加する前はこのように表示されるが: 87 | 88 | ![Before, tab space example](http://i.imgur.com/GIT1Fr0.png) 89 | 90 | `?ts=4`を追加するとこのように表示される: 91 | 92 | ![After, tab space example](http://i.imgur.com/70FL4H9.png) 93 | 94 | ### 特定のユーザーによるコミット履歴 95 | 特定のユーザーによるあるリポジトリへのコミット履歴のみを参照したい場合は、`?author={user}`をURLの末尾に付ける。 96 | 97 | ``` 98 | https://github.com/rails/rails/commits/master?author=dhh 99 | ``` 100 | ![DHH commit history](http://i.imgur.com/S7AE29b.png) 101 | 102 | [*コミット・ビューの違いについてもっと詳しく*](https://help.github.com/articles/differences-between-commit-views) 103 | 104 | ### リポジトリのクローン 105 | リポジトリをクローンする時、URLの末尾の`.git`は無くても構わない。 106 | 107 | ```bash 108 | $ git clone https://github.com/tiimgreen/github-cheat-sheet 109 | ``` 110 | 111 | [*Gitの`clone`コマンドについてもっと詳しく*](http://git-scm.com/docs/git-clone) 112 | 113 | ### ブランチ 114 | #### 全ブランチを別のブランチと比較 115 | コミット一覧ボタンの隣から[ブランチ一覧](https://github.com/tiimgreen/github-cheat-sheet/branches)ページに行くと: 116 | 117 | ``` 118 | https://github.com/{user}/{repo}/branches 119 | ``` 120 | 121 | メイン・ブランチにマージされていないブランチの一覧が表示される。 122 | 123 | このページからボタンをクリックしてブランチ比較ページへ移動したりブランチを削除することができる。 124 | 125 | ![Compare branches not merged into master in rails/rails repo - https://github.com/rails/rails/branches](http://i.imgur.com/0FEe30z.png) 126 | 127 | #### ブランチ同士の比較 128 | GitHubのブランチ比較は以下のようなURLで提供されている: 129 | 130 | ``` 131 | https://github.com/{user}/{repo}/compare/{range} 132 | ``` 133 | 134 | `{range}`を`master...4-1-stable`に変更する。 135 | 136 | 例えば: 137 | 138 | ``` 139 | https://github.com/rails/rails/compare/master...4-1-stable 140 | ``` 141 | ![Rails branch compare example](http://i.imgur.com/tIRCOsK.png) 142 | 143 | `{range}`には以下のように変更することもできる: 144 | 145 | ``` 146 | https://github.com/rails/rails/compare/master@{1.day.ago}...master 147 | https://github.com/rails/rails/compare/master@{2014-10-04}...master 148 | ``` 149 | 150 | *日付の形式は`YYYY-MM-DD`だ。* 151 | 152 | ![Another compare example](http://i.imgur.com/5dtzESz.png) 153 | 154 | `diff`や`patch`のビューでもブランチを利用して比較することができる: 155 | 156 | ``` 157 | https://github.com/rails/rails/compare/master...4-1-stable.diff 158 | https://github.com/rails/rails/compare/master...4-1-stable.patch 159 | ``` 160 | 161 | [*時間を指定してのブランチ比較についてもっと詳しく*](https://help.github.com/articles/comparing-commits-across-time) 162 | 163 | #### フォークされたリポジトリ間でのブランチ比較 164 | GitHubでフォークされたリポジトリ同士でブランチを比較する場合、以下のようなURLを変更する: 165 | 166 | ``` 167 | https://github.com/user/repo/compare/{foreign-user}:{branch}...{own-branch} 168 | ``` 169 | 170 | 例: 171 | 172 | ``` 173 | https://github.com/rails/rails/compare/byroot:master...master 174 | ``` 175 | 176 | ![Forked branch compare](http://i.imgur.com/Q1W6qcB.png) 177 | 178 | ### Gists 179 | [Gists](https://gist.github.com/)は少量のコード群を管理する最適な手段だ。ちゃんとしたリポジトリをいちいち作成する必要はない。 180 | 181 | ![Gist](http://i.imgur.com/VkKI1LC.png?1) 182 | 183 | GistのURLの最後に`.pibb`を付ける([例](https://gist.github.com/hail2u/9477708.pibb))と*HTMLのみ*のバージョンが表示されるので、そのソースは他のウェブサイトに貼り付けるにはもってこいだろう。 184 | 185 | 簡単なものとはいえ、Gitリポジトリとして機能するため、以下のようにすれば普通のGitリポジトリと同じようにクローンすることができる: 186 | 187 | ```bash 188 | $ git clone https://gist.github.com/tiimgreen/10545817 189 | ``` 190 | 191 | ![Gists](http://i.imgur.com/BcFzabp.png) 192 | 193 | This means you also can modify and push updates to Gists: 194 | 195 | ```bash 196 | $ git commit 197 | $ git push 198 | Username for 'https://gist.github.com': 199 | Password for 'https://tiimgreen@gist.github.com': 200 | ``` 201 | 202 | しかしながら、Gistではディレクトリーがサポートされていない。全てのファイルはリポジトリーのルートに置かれている必要がある。 203 | 204 | [*Gistの作成についてもっと詳しく*](https://help.github.com/articles/creating-gists) 205 | 206 | ### Git.io 207 | [Git.io](http://git.io)はGitHubの提供するGitHub専用のシンプルな短縮URLサービスだ。 208 | 209 | ![Git.io](http://i.imgur.com/6JUfbcG.png?1) 210 | 211 | cURLを使って利用することができる: 212 | 213 | ```bash 214 | $ curl -i http://git.io -F "url=https://github.com/..." 215 | HTTP/1.1 201 Created 216 | Location: http://git.io/abc123 217 | 218 | $ curl -i http://git.io/abc123 219 | HTTP/1.1 302 Found 220 | Location: https://github.com/... 221 | ``` 222 | 223 | [*Git.ioについてもっと詳しく*](https://github.com/blog/985-git-io-github-url-shortener) 224 | 225 | ### キーボード・ショートカット 226 | リポジトリをブラウザーで開いている時は、ショートカットを利用して様々な機能ヘ簡単にアクセスできるようになっている。 227 | 228 | - `t`を押すとファイルの検索インターフェイスが起動する。 229 | - `w`を押すとブランチ選択インターフェイスが起動する。 230 | - `s`を押すと現在閲覧しているリポジトリーから検索するフォームにフォーカスが当たる。ここでBackspaceを押し「This repository」という文字列を消すことでGitHub全体からの検索へと切り替えることができる 231 | - issue画面で`l`を押すとラベルの編集インターフェイスが開かれる。 232 | - __ファイルを参照している時__(例: `https://github.com/tiimgreen/github-cheat-sheet/blob/master/README.md`)に`y`を押すと、参照している時の状態で固定されるURLに変更される。つまりそのファイルのコードが後に変化したとしても、そのURLでは今とまったく同じ状態で表示されるということだ。 233 | 234 | `?`を押すとそのページで使える全ショートカットが表示されるだろう。 235 | 236 | ![Keyboard shortcuts](http://i.imgur.com/y5ZfNEm.png) 237 | 238 | [*検索機能についてもっと詳しく*](https://help.github.com/articles/search-syntax/) 239 | 240 | ### コードの指定行の強調 241 | コードのURLの末尾に`#L52`と付けるか行番号をクリックすると、その行が強調表示される。 242 | 243 | これは範囲指定も可能だ(例: `#L53-L60`)。こういった範囲を選択するには`shift`を押しながら二つの行をクリックしても良い: 244 | 245 | ``` 246 | https://github.com/rails/rails/blob/master/activemodel/lib/active_model.rb#L53-L60 247 | ``` 248 | 249 | ![Line Highlighting](http://i.imgur.com/8AhjrCz.png) 250 | 251 | ### コミットからissueを閉じる 252 | あるコミットでissueを解決した場合、コミットメッセージで`fix/fixes/fixed`や`close/closes/closed`、`resolve/resolves/resolved`に続けてissue番号を指定すると、そのコミットがmasterブランチにpushされると同時に指定issueが閉じられるだろう。 253 | 254 | ```bash 255 | $ git commit -m "Fix screwup, fixes #12" 256 | ``` 257 | 258 | こうするとissue#12が閉じられ、閉じたissueにはそのコミットへの参照が自動的に追加される。 259 | 260 | ![Closing Repo](http://i.imgur.com/Uh1gZdx.png) 261 | 262 | [*コミット・メッセージからissueを閉じる方法についてもっと詳しく*](https://help.github.com/articles/closing-issues-via-commit-messages) 263 | 264 | ### issueの相互リンク 265 | 同じリポジトリの違うissueへリンクを張り参照させたい場合、`#`に続けてissue番号を指定する。そうすると自動的にリンクが作成されるだろう。 266 | 267 | 別のリポジトリのissueの場合は`{user}/{repo}#ISSUE_NUMBER`とすれば良い(例: `tiimgreen/toc#12`)。 268 | 269 | ![Cross-Link Issues](https://camo.githubusercontent.com/447e39ab8d96b553cadc8d31799100190df230a8/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f7265666572656e6365732e706e67) 270 | 271 | ### コメントのロック 272 | リポジトリのオーナーや共同開発者ならば、pull requestやissueへのコメントをロックできるようになった。 273 | 274 | ![Lock conversation](https://cloud.githubusercontent.com/assets/2723/3221693/bf54dd44-f00d-11e3-8eb6-bb51e825bc2c.png) 275 | 276 | つまりそのプロジェクトの共同開発者ではないユーザーはコメントをすることができないということだ。 277 | 278 | ![Comments locked](https://cloud.githubusercontent.com/assets/2723/3221775/d6e513b0-f00e-11e3-9721-2131cb37c906.png) 279 | 280 | [*コメントのロックについてもっと詳しく*](https://github.com/blog/1847-locking-conversations) 281 | 282 | ### pull requestでのCI結果の表示 283 | 適切に設定を行えばpull requestを受け取るたびに、通常のコミットと同じように[Travis CI](https://travis-ci.org/)がそのpull requestをビルドするだろう。どう設定するかは[Travis CI: Getting started](http://docs.travis-ci.com/user/getting-started/)を読むと良い。 284 | 285 | [![Travis CI status](https://cloud.githubusercontent.com/assets/1687642/2700187/3a88838c-c410-11e3-9a46-e65e2a0458cd.png)](https://github.com/octokit/octokit.rb/pull/452) 286 | 287 | [*コミット・ステータスAPIについてもっと詳しく*](https://github.com/blog/1227-commit-status-api) 288 | 289 | ### 絞り込み検索 290 | issueとpull requestの検索インターフェイスでは、絞り込みをかけることが可能だ。 291 | 292 | 例えば[Railsのリポジトリー](https://github.com/rails/rails/issues)では、以下の様な絞り込み検索により"activerecord"というラベルがついたissueのみを表示することができる: 293 | 294 | `is:issue label:activerecord` 295 | 296 | 逆に"activerecord"というラベルが*ついていない*issueのみを表示することもできる: 297 | 298 | `is:issue -label:activerecord` 299 | 300 | そして、この絞り込み検索はpull requestに対しても行うことができる: 301 | 302 | `is:pr -label:activerecord` 303 | 304 | GitHubでは開かれているissueやpull requestのみを表示するタブ、または既に閉じられたそれらのみを表示するタブが用意されているが、絞り込み検索によってマージ済みのpull requestのみを表示することもできる。以下のようなフィルターを使えば良いだろう: 305 | 306 | `is:merged` 307 | 308 | [*issueの検索についてもっと詳しく*](https://help.github.com/articles/searching-issues) 309 | 310 | そしてGitHubはStatus APIの結果を使ってフィルターすることもできるようになった。 311 | 312 | Status APIでsuccessが設定されたpull requestのみ: 313 | 314 | `status:success` 315 | 316 | [*Status APIを使った絞り込み検索についてもっと詳しく*](https://github.com/blog/2014-filter-pull-requests-by-status) 317 | 318 | ### Markdownファイルでの構文強調 319 | 例えばMarkdownファイルでRubyのコードを構文強調したいならば以下のようにする: 320 | 321 | ```ruby 322 | require 'tabbit' 323 | table = Tabbit.new('Name', 'Email') 324 | table.add_row('Tim Green', 'tiimgreen@gmail.com') 325 | puts table.to_s 326 | ``` 327 | 328 | こうすると以下のように表示されることになる: 329 | 330 | ```ruby 331 | require 'tabbit' 332 | table = Tabbit.new('Name', 'Email') 333 | table.add_row('Tim Green', 'tiimgreen@gmail.com') 334 | puts table.to_s 335 | ``` 336 | 337 | GitHubでは[Linguist](https://github.com/github/linguist)を使って言語を判別し構文強調を行っている。構文強調がサポートされている言語の一覧は[言語定義YAMLファイル](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml)を参照すればわかるだろう。 338 | 339 | [*GitHub Flavored Markdownについてもっと詳しく*](https://help.github.com/articles/github-flavored-markdown) 340 | 341 | ### Emoji 342 | Emojiはpull requestやissue、コミット・メッセージ、リポジトリーの概要などで`:name_of_emoji:`と書くと利用できる: 343 | 344 | GitHubでサポートされているEmojiの完全なリストは[Emoji cheat sheet for Campfire and GitHub](http://www.emoji-cheat-sheet.com/)か[All-Github-Emoji-Icons](https://github.com/scotch-io/All-Github-Emoji-Icons)で確認できる。 345 | 素敵なemojiの検索は[emoji.muan.co](http://emoji.muan.co/)。 346 | 347 | GitHubで使われているEmojiのトップ5は以下の通りだ: 348 | 349 | 1. `:shipit:` 350 | 2. `:sparkles:` 351 | 3. `:-1:` 352 | 4. `:+1:` 353 | 5. `:clap:` 354 | 355 | ### 画像及びアニメーションGIF 356 | 画像やアニメーションGIFはコミットのコメントやREADMEなどで利用できる: 357 | 358 | ``` 359 | ![Alt Text](http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif) 360 | ``` 361 | 362 | リポジトリにある画像も直接参照することが出来る: 363 | 364 | ``` 365 | ![Alt Text](https://github.com/{user}/{repo}/raw/master/path/to/image.gif) 366 | ``` 367 | 368 | ![Peter don't care](http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif) 369 | 370 | あらゆる画像はGitHubでキャッシュされるので、画像のホスティング先が落ちていたとしても変わらず表示されるだろう。 371 | 372 | #### GitHub Wikiへの画像の添付 373 | GitHub Wikiで画像を追加する方法がいくつかある。通常のMarkdown記法(前節を参照)はもちろん使える。しかしそれだけではなく、画像の幅と高さを指定する記法も使うことができる: 374 | 375 | ```markdown 376 | [[ http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif | height = 100px ]] 377 | ``` 378 | 379 | こうすると以下のようになる: 380 | 381 | ![Just a screenshot](http://i.imgur.com/J5bMf7S.png) 382 | 383 | ### 素早く引用 384 | issueのスレッドで他の人のコメントを引用してコメントしたい場合、引用したい文章を選択した状態で`r`を押すと、ブロック引用の記法を使ってテキストエリアにコピーされる。 385 | 386 | ![Quick Quote](http://i.imgur.com/TzpMIOA.png) 387 | 388 | [*素早く引用する方法についてもっと詳しく*](https://github.com/blog/1399-quick-quotes) 389 | 390 | ### コメントへのクリップボードの画像の追加 391 | 392 | _(Chrome系のブラウザーのみで動作)_ 393 | 394 | スクリーンショットをクリップボードに保存(mac: `cmd-ctrl-shift-4`)した後、その画像はコメント投稿フォームで貼り付け(`cmd-v`または`ctrl-v`)ることができ、自動的にGitHubへアップロードされます。 395 | 396 | ![Pasting Clipboard Image to Comments](https://cloud.githubusercontent.com/assets/39191/5794265/39c9b65a-9f1b-11e4-9bc7-04e41f59ea5f.png) 397 | 398 | [*コメントへのクリップボードの画像の追加についてもっと詳しく*](https://help.github.com/articles/issue-attachments) 399 | 400 | ### 設定済みライセンスの追加 401 | GitHub上でリポジトリを作成する時、あらかじめ設定されているライセンスを追加することもできる: 402 | 403 | ![Licese](http://i.imgur.com/Chqj4Fg.png) 404 | 405 | 既に存在するリポジトリであってもウェブ上のインターフェイスからファイルを作成することで追加できる。`LICENSE`というファイル名にした場合、ライセンスを選択するオプションが表示されるのだ: 406 | 407 | ![License](http://i.imgur.com/fTjQict.png) 408 | 409 | `.gitignore`も同じように作成時に追加することも、後で追加することもできる。 410 | 411 | [*オープンソース・ライセンスについてもっと詳しく*](https://help.github.com/articles/open-source-licensing) 412 | 413 | ### タスクリスト 414 | issueやpull requestでは以下のように(空白に注意)書くとチェックボックスを作成することができる: 415 | 416 | ``` 417 | - [ ] Be awesome 418 | - [ ] Prepare dinner 419 | - [ ] Research recipe 420 | - [ ] Buy ingredients 421 | - [ ] Cook recipe 422 | - [ ] Sleep 423 | ``` 424 | 425 | ![Task List](http://i.imgur.com/jJBXhsY.png) 426 | 427 | これらチェックボックスにチェックが入れられると、同時にMarkdownソースも更新される: 428 | 429 | ``` 430 | - [x] Be awesome 431 | - [ ] Prepare dinner 432 | - [x] Research recipe 433 | - [x] Buy ingredients 434 | - [ ] Cook recipe 435 | - [ ] Sleep 436 | ``` 437 | 438 | [*タスク・リストについてもっと詳しく*](https://help.github.com/articles/writing-on-github#task-lists) 439 | 440 | #### Markdownファイルでのタスクリスト 441 | 通常のMarkdownファイルでも**読み取り専用**のチェックリストを以下のような記法で追加することができる: 442 | 443 | ``` 444 | - [ ] Mercury 445 | - [x] Venus 446 | - [x] Earth 447 | - [x] Mars 448 | - [ ] Jupiter 449 | ``` 450 | 451 | - [ ] Mercury 452 | - [x] Venus 453 | - [x] Earth 454 | - [x] Mars 455 | - [ ] Jupiter 456 | 457 | [*Markdownファイルでのタスクリストについてもっと詳しく*](https://github.com/blog/1825-task-lists-in-all-markdown-documents) 458 | 459 | ### 相対リンク 460 | Markdownファイルでリポジトリ内のコンテンツへ張る場合、相対リンクを利用することが推奨されている。 461 | 462 | ```markdown 463 | [Link to a header](#awesome-section) 464 | [Link to a file](docs/readme) 465 | ``` 466 | 467 | 絶対リンクはURLの変更(例: リポジトリのリネーム、ユーザー名の変更、プロジェクトのフォーク)により更新される。相対リンクを利用すれば、そのままうまく機能するはずだ。 468 | 469 | [*相対リンクについてもっと詳しく*](https://help.github.com/articles/relative-links-in-readmes) 470 | 471 | ### GitHub Pagesでのメタデータとプラグインのサポート 472 | Jekyllのページや投稿ではリポジトリの情報が`site.github`という名前空間に格納されており、例えば`{{ site.github.project_title }}`などと書けば表示することができる。 473 | 474 | また、Jemojiとjekyll-mentionsというプラグインがインストールされているので、[Emoji](#emoji)や[@mentions](https://github.com/blog/821)はJekyllの投稿やページでGitHub.com上と同じように動作する。 475 | 476 | [*GitHub Pageでのメタデータとプラグインのサポートについてもっと詳しく*](https://github.com/blog/1797-repository-metadata-and-plugin-support-for-github-pages) 477 | 478 | ### 文書内のYAMLメタデータ 479 | [Jekyll](http://jekyllrb.com/)を[GitHub Pages](http://pages.github.com/)で利用している場合など、多くのブログではYAML形式のメタデータをその記事の先頭に書く必要がある。GitHubではこういったメタデータを読みやすいように表として表示してくれる: 480 | 481 | ![YAML metadata](https://camo.githubusercontent.com/47245aa16728e242f74a9a324ce0d24c0b916075/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f36343035302f313232383236372f65303439643063362d323761302d313165332d396464382d6131636432323539393334342e706e67) 482 | 483 | [*文書内のYAMLメタデータの表示についてもっと詳しく*](https://github.com/blog/1647-viewing-yaml-metadata-in-your-documents) 484 | 485 | ### 表形式のデータ表示 486 | GitHubでは`.csv`(カンマ区切り)と`.tsv`(タブ区切り)の形式で書かれた表を整形して表示する機能をサポートしている。 487 | 488 | ![Tabular data](https://camo.githubusercontent.com/1b6dd0157ffb45d9939abf14233a0cb13b3b4dfe/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3238323735392f3937363436322f33323038336463652d303638642d313165332d393262322d3566323863313061353035392e706e67) 489 | 490 | [*表形式のデータ表示についてもっと詳しく*](https://github.com/blog/1601-see-your-csvs) 491 | 492 | ### PDF表示 493 | GitHubではPDFの表示をサポートしている: 494 | 495 | ![PDF](https://cloud.githubusercontent.com/assets/1000669/7492902/f8493160-f42e-11e4-8cea-1cb4f02757e7.png) 496 | 497 | [*PDF表示についてもっと詳しく*](https://github.com/blog/1974-pdf-viewing) 498 | 499 | ### pull requestの取り消し 500 | pull requestをマージした後、意味がなかったことがわかったり、そのpull requestをマージしたのは間違いだったことがわかることもあるだろう。 501 | 502 | その取り消しは、pull requestのページに表示されているマージ・コミットの右端にある**Revert**ボタンをクリックすることにより、そのpull requestで行われた変更を取り消すpull requestを作成することによって行うことができる。 503 | 504 | ![Revert button](https://camo.githubusercontent.com/0d3350caf2bb1cba53123ffeafc00ca702b1b164/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f68656c702f70756c6c5f72657175657374732f7265766572742d70756c6c2d726571756573742d6c696e6b2e706e67) 505 | 506 | [*pull requestの取り消しについてもっと詳しく*](https://github.com/blog/1857-introducing-the-revert-button) 507 | 508 | ### 差分の表示 509 | #### レンダリング済みの差分表示 510 | コミットやpull requestにGitHubでレンダリングされて表示されるもの(例: Markdown)が含まれる場合、その*ソース*と*レンダリング済み*の両方の差分を見ることができる。 511 | 512 | ![Source / Rendered view](https://github-images.s3.amazonaws.com/help/repository/rendered_prose_diff.png) 513 | 514 | レンダリングされた状態での差分を表示したい場合は「Rendered」ボタンをクリックする。レンダリング済みの差分表示では文章の追加や削除、編集がよりわかりやすい: 515 | 516 | ![Rendered Prose Diffs](https://f.cloud.github.com/assets/17715/2003056/3997edb4-862b-11e3-90be-5e9586edecd7.png) 517 | 518 | [*レンダリング済みの差分表示についてもっと詳しく*](https://github.com/blog/1784-rendered-prose-diffs) 519 | 520 | #### マップ差分の可視化 521 | コミットやpull requestにジオデータの変更が含まれている場合はいつも、GitHubではそのジオデータの変化を可視化してくれるだろう。 522 | 523 | [![Diffable Maps](https://f.cloud.github.com/assets/282759/2090660/63f2e45a-8e97-11e3-9d8b-d4c8078b004e.gif)](https://github.com/benbalter/congressional-districts/commit/2233c76ca5bb059582d796f053775d8859198ec5) 524 | 525 | [*マップ差分の可視化についてもっと詳しく*](https://github.com/blog/1772-diffable-more-customizable-maps) 526 | 527 | #### 差分表示の前後を表示 528 | 差分表示の行番号付近にある*展開*ボタンを使うと、その前後の行をクリックして表示させることができる。*展開*ボタンを押し続けることによってファイル全体を表示することもできるし、またこの機能はあらゆるGitHubの差分表示ビューに用意されている。 529 | 530 | ![Expanding Context in Diffs](https://f.cloud.github.com/assets/22635/1610539/863c1f64-5584-11e3-82bf-151b406a272f.gif) 531 | 532 | [*差分表示の前後を表示についてもっと詳しく*](https://github.com/blog/1705-expanding-context-in-diffs) 533 | 534 | #### pull requestの内容をDIFFまたはPATCH形式で取得 535 | pull requestによる差分はそのURLの末尾に`.diff`または`.patch`を追加すると、それぞれの形式で取得することができる。例えば: 536 | 537 | ``` 538 | https://github.com/tiimgreen/github-cheat-sheet/pull/15 539 | https://github.com/tiimgreen/github-cheat-sheet/pull/15.diff 540 | https://github.com/tiimgreen/github-cheat-sheet/pull/15.patch 541 | ``` 542 | 543 | 拡張子`.diff`を追加した場合、このようなプレーンテキストで表示されるだろう: 544 | 545 | ``` 546 | diff --git a/README.md b/README.md 547 | index 88fcf69..8614873 100644 548 | --- a/README.md 549 | +++ b/README.md 550 | @@ -28,6 +28,7 @@ All the hidden and not hidden features of Git and GitHub. This cheat sheet was i 551 | - [Merged Branches](#merged-branches) 552 | - [Quick Licensing](#quick-licensing) 553 | - [TODO Lists](#todo-lists) 554 | +- [Relative Links](#relative-links) 555 | - [.gitconfig Recommendations](#gitconfig-recommendations) 556 | - [Aliases](#aliases) 557 | - [Auto-correct](#auto-correct) 558 | @@ -381,6 +382,19 @@ When they are clicked, they will be updated in the pure Markdown: 559 | - [ ] Sleep 560 | 561 | (...) 562 | ``` 563 | 564 | #### 画像の表示とDIFF 565 | GitHubは、PNGやJPG、GIF、PSDといった多くの一般的な画像形式の表示をサポートしている。それに加え、様々な方法でこれら画像形式のバージョンごとの差分を比較することもできる。 566 | 567 | [![Diffable PSD](https://cloud.githubusercontent.com/assets/2546/3165594/55f2798a-eb56-11e3-92e7-b79ad791a697.gif)](https://github.com/blog/1845-psd-viewing-diffing) 568 | 569 | [*画像の表示とDIFFについてもっと詳しく*](https://help.github.com/articles/rendering-and-diffing-images) 570 | 571 | ### Hub 572 | [Hub](https://github.com/github/hub)はGitのラッパーとして機能するコマンドライン・ツールで、これを利用するとGitHubをコマンドラインからとても簡単に扱えるようになる。 573 | 574 | 例えば以下のようにしてリポジトリのクローンが行える: 575 | 576 | ```bash 577 | $ hub clone tiimgreen/toc 578 | ``` 579 | 580 | これが以下のコマンドの代わりというわけだ: 581 | 582 | ```bash 583 | $ git clone https://github.com/tiimgreen/toc.git 584 | ``` 585 | 586 | [*Hubが提供する便利な機能についてもっと詳しく*](https://github.com/github/hub#commands) 587 | 588 | ### 開発参加のガイドライン 589 | リポジトリのルートに`CONTRIBUTING`という名前のファイルを置くと、issueやpull requestを作成しようとした時にそれへのリンクが表示されるようになる。 590 | 591 | ![Contributing Guidelines](https://camo.githubusercontent.com/71995d6b0e620a9ef1ded00a04498241c69dd1bf/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f736b697463682f6973737565732d32303132303931332d3136323533392e6a7067) 592 | 593 | [*開発参加のガイドラインについてもっと詳しく*](https://github.com/blog/1184-contributing-guidelines) 594 | 595 | ### Octicons 596 | GitHubで使われているアイコン(Octicons)はオープンソース化された。 597 | 598 | ![Octicons](https://og.github.com/octicons/octicons@1200x630.png) 599 | 600 | [*GitHubのOcticonsについてもっと詳しく*](https://octicons.github.com) 601 | 602 | ### GitHub情報 603 | | Title | Link | 604 | | ----- | ---- | 605 | | GitHub Explore | https://github.com/explore | 606 | | GitHub Blog | https://github.com/blog | 607 | | GitHub Help | https://help.github.com/ | 608 | | GitHub Training | http://training.github.com/ | 609 | | GitHub Developer | https://developer.github.com/ | 610 | 611 | #### GitHub Talks 612 | | Title | Link | 613 | | ----- | ---- | 614 | | How GitHub Uses GitHub to Build GitHub | https://www.youtube.com/watch?v=qyz3jkOBbQY | 615 | | Introduction to Git with Scott Chacon of GitHub | https://www.youtube.com/watch?v=ZDR433b0HJY | 616 | | How GitHub No Longer Works | https://www.youtube.com/watch?v=gXD1ITW7iZI | 617 | | Git and GitHub Secrets | https://www.youtube.com/watch?v=Foz9yvMkvlA | 618 | | More Git and GitHub Secrets | https://www.youtube.com/watch?v=p50xsL-iVgU | 619 | 620 | ## Git 621 | ### すべての削除済みファイルをワーキング・ツリーから削除する 622 | 例えば`/bin/rm`を使って大量のファイルを削除した場合、以下のコマンドを使えばワーキング・ツリー、そしてインデックスからも削除することができ、ファイルごとにそれぞれGitコマンドを実行する必要がなくなる: 623 | 624 | ```bash 625 | $ git rm $(git ls-files -d) 626 | ``` 627 | 628 | 例えば以下のように実行される: 629 | 630 | ```bash 631 | $ git status 632 | On branch master 633 | Changes not staged for commit: 634 | deleted: a 635 | deleted: c 636 | 637 | $ git rm $(git ls-files -d) 638 | rm 'a' 639 | rm 'c' 640 | 641 | $ git status 642 | On branch master 643 | Changes to be committed: 644 | deleted: a 645 | deleted: c 646 | ``` 647 | 648 | ### 直前のブランチ 649 | Gitで直前のブランチへ移動するには: 650 | 651 | ```bash 652 | $ git checkout - 653 | # Switched to branch 'master' 654 | 655 | $ git checkout - 656 | # Switched to branch 'next' 657 | 658 | $ git checkout - 659 | # Switched to branch 'master' 660 | ``` 661 | 662 | [*Gitのブランチ操作についてもっと詳しく*](http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging) 663 | 664 | ### 空白の削除 665 | Gitの`stripspace`コマンドは以下の作業を行う: 666 | 667 | - 行末の空白文字の削除 668 | - 空白行の取りまとめ 669 | - ファイル末尾への改行の追加 670 | 671 | このコマンドを呼ぶ時はファイルを渡さねばならない。例: 672 | 673 | ```bash 674 | $ git stripspace < README.md 675 | ``` 676 | 677 | [*Gitの`stripspace`コマンドについてもっと詳しく*](http://git-scm.com/docs/git-stripspace) 678 | 679 | ### SSH公開鍵 680 | 以下のURLにアクセスすることで、SSH公開鍵の一覧をテキスト形式で取得することができる: 681 | 682 | ``` 683 | https://github.com/{user}.keys 684 | ``` 685 | 686 | 例: [https://github.com/tiimgreen.keys](https://github.com/tiimgreen.keys) 687 | 688 | [*SSH公開鍵についてもっと詳しく*](https://changelog.com/github-exposes-public-ssh-keys-for-its-users/) 689 | 690 | ### pull requestのチェックアウト 691 | pull requestはGitHubのリポジトリでは特別なブランチであり、様々な方法でローカルに取り込むことができる: 692 | 693 | 特定のpull requestを取り込み、一時的に`FETCH_HEAD`として保存すると、素早く差分を確認してマージすることが可能だ: 694 | 695 | ```bash 696 | $ git fetch origin refs/pull/[PR-Number]/head 697 | ``` 698 | 699 | 参照仕様を使うとすべてのpull requestをローカル・ブランチとして取り込むことができる: 700 | 701 | ```bash 702 | $ git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*' 703 | ``` 704 | 705 | リポジトリの`.git/config`に以下の行を追加すれば自動的にpull requestを落とすようにもできるだろう: 706 | 707 | ``` 708 | [remote "origin"] 709 | fetch = +refs/heads/*:refs/remotes/origin/* 710 | url = git@github.com:tiimgreen/github-cheat-sheet.git 711 | ``` 712 | 713 | ``` 714 | [remote "origin"] 715 | fetch = +refs/heads/*:refs/remotes/origin/* 716 | url = git@github.com:tiimgreen/github-cheat-sheet.git 717 | fetch = +refs/pull/*/head:refs/remotes/origin/pr/* 718 | ``` 719 | 720 | フォークされてから送られてきたpull requestに対しては、そのpull requestを参照するリモート・ブランチから直接ローカル・ブランチとしてチェックアウトすると便利だろう: 721 | 722 | ```bash 723 | $ git checkout pr/42 pr-42 724 | ``` 725 | 726 | もしくは様々なリポジトリで作業をするのなら、代わりにグローバルのGit設定で行うことにより、pull requestの取得をグローバルに設定すると良いだろう。 727 | 728 | ```bash 729 | git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*" 730 | ``` 731 | 732 | こうすると以下の様な短いコマンドを利用することが可能になる: 733 | 734 | ```bash 735 | git fetch origin 736 | ``` 737 | 738 | ```bash 739 | git checkout pr/42 740 | ``` 741 | 742 | [*pull requestのチェックアウトについてもっと詳しく*](https://help.github.com/articles/checking-out-pull-requests-locally) 743 | 744 | ### 空のコミット 745 | `--allow-empty`オプションを付けると、コードの変化がなくてもコミットを作成することができる: 746 | 747 | ```bash 748 | $ git commit -m "Big-ass commit" --allow-empty 749 | ``` 750 | 751 | この機能の使い方(便利なもの)としては以下のようなものが挙げられる: 752 | 753 | - 新たな機能や大きな変更を事前に通知する時 754 | - コード上に現れないような変更をプロジェクトに加えた時 755 | - リポジトリを利用して誰かと連絡を取りたい時 756 | - リポジトリへの最初のコミットをやり直しできるようにしたい時: `git commit -m "init repo" --allow-empty`. 757 | 758 | ### Gitステータスのスタイリング 759 | 普通に実行すると: 760 | 761 | ```bash 762 | $ git status 763 | ``` 764 | 765 | このように表示されるが: 766 | 767 | ![git status](http://i.imgur.com/qjPyvXb.png) 768 | 769 | `-sb`を追加することによって: 770 | 771 | ```bash 772 | $ git status -sb 773 | ``` 774 | 775 | このように表示することもできる: 776 | 777 | ![git status -sb](http://i.imgur.com/K0OY3nm.png) 778 | 779 | [*Gitの`status`コマンドについてもっと詳しく*](http://git-scm.com/docs/git-status) 780 | 781 | ### Gitログのスタイリング 782 | 以下のように実行すると: 783 | 784 | ```bash 785 | $ git log --all --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative 786 | ``` 787 | 788 | このように表示される: 789 | 790 | ![git log --all --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative](http://i.imgur.com/58eOtkW.png) 791 | 792 | この設定は[Palesz](http://stackoverflow.com/users/88355/palesz)が考えたものだ。 793 | 794 | *これは[後述の手順](#%E3%82%A8%E3%82%A4%E3%83%AA%E3%82%A2%E3%82%B9)に従ってエイリアスへ追加することもできる。* 795 | 796 | [*Gitの`log`コマンドについてもっと詳しく*](http://git-scm.com/docs/git-log) 797 | 798 | ### コミットログの検索 799 | 指定した文字列を今までのコミット・メッセージから検索して、もっとも新しいものを表示することができる。 800 | 801 | ```bash 802 | $ git show :/query 803 | ``` 804 | 805 | `query`を検索したい文字列(大文字と小文字を区別する)で置き換えると、最新のコミットがそのコミットにおける差分と同時に表示される。 806 | 807 | ```bash 808 | $ git show :/typo 809 | ``` 810 | ![git show :/query](http://i.imgur.com/icaGiNt.png) 811 | 812 | 注: 終了するには`q`を押す。 813 | 814 | ### Git Grep 815 | Git Grepは指定したパターンに一致する行の一覧を返してくれる。 816 | 817 | 実行すると: 818 | 819 | ```bash 820 | $ git grep aliases 821 | ``` 822 | 823 | *aliases*という文字を含むファイルを全て表示することだろう。 824 | 825 | ![git grep aliases](http://i.imgur.com/DL2zpQ9.png) 826 | 827 | 注: 終了するには`q`を押す。 828 | 829 | 複数のフラグを組み合わせることで、より高度な検索を行うことができる。例えば: 830 | 831 | * `-e` 次のパラメーターをパターンとする (例: regex) 832 | * `--and`、`--or`と`--not` 複数のパターンを組み合わせる 833 | 834 | 以下のようにして使う: 835 | 836 | ```bash 837 | $ git grep -e pattern --and -e anotherpattern 838 | ``` 839 | 840 | [*Gitの`grep`コマンドについてもっと詳しく*](http://git-scm.com/docs/git-grep) 841 | 842 | ### マージ済みブランチ 843 | 以下のように実行すると: 844 | 845 | ```bash 846 | $ git branch --merged 847 | ``` 848 | 849 | 現在のブランチに既にマージされたブランチの一覧が表示される。 850 | 851 | 逆に: 852 | 853 | ```bash 854 | $ git branch --no-merged 855 | ``` 856 | 857 | こうするとまだマージされていないブランチが表示されるだろう。 858 | 859 | [*Gitの`branch`コマンドについてもっと詳しく*](http://git-scm.com/docs/git-branch) 860 | 861 | ### FixupとAutosquash 862 | これまでのコミット(HEADの直前でなくても構わない)、例えば`abcde`というチェックサムのコミットで何か問題を見つけた場合、以下の様なコマンドで問題の修正を行うことができる: 863 | 864 | ```bash 865 | $ git commit --fixup=abcde 866 | $ git rebase abcde^ --autosquash -i 867 | ``` 868 | 869 | [*Gitの`commit`コマンドについてもっと詳しく*](http://git-scm.com/docs/git-commit) 870 | [*Gitの`rebase`コマンドについてもっと詳しく*](http://git-scm.com/docs/git-rebase) 871 | 872 | ### ローカル・リポジトリを参照するウェブサーバー 873 | Gitの`instaweb`コマンドを利用すると、自分の作業リポジトリを`gitweb`で参照することができる。このコマンドは`gitweb`とウェブサーバーをセットアップしてローカル・リポジトリをブラウザーで開けるようにする簡単なスクリプトだ。 874 | 875 | ```bash 876 | $ git instaweb 877 | ``` 878 | 879 | 以下のようなページが開かれる: 880 | 881 | ![Git instaweb](http://i.imgur.com/Dxekmqc.png) 882 | 883 | [*Gitの`instaweb`コマンドについてもっと詳しく*](http://git-scm.com/docs/git-instaweb) 884 | 885 | ### Gitの設定 886 | `.gitconfig`とはあらゆる設定が書き込まれるファイルだ。 887 | 888 | #### エイリアス 889 | エイリアスはGitの呼び出し方を自分で好きなように定義できるヘルパー機能だ。例えば`git a`で`git add --all`を実行するようにすることができる。 890 | 891 | エイリアスを追加するには`~/.gitconfig`を開き、以下のような形式で記述していく: 892 | 893 | ``` 894 | [alias] 895 | co = checkout 896 | cm = commit 897 | p = push 898 | # Show verbose output about tags, branches or remotes 899 | tags = tag -l 900 | branches = branch -a 901 | remotes = remote -v 902 | ``` 903 | 904 | またはコマンドラインからも設定できる: 905 | 906 | ```bash 907 | $ git config --global alias.new_alias git_function 908 | ``` 909 | 910 | 例: 911 | 912 | ```bash 913 | $ git config --global alias.cm commit 914 | ``` 915 | 916 | 注: エイリアスが複数のコマンドからなる場合はクオートで括る必要がある: 917 | 918 | ```bash 919 | $ git config --global alias.ac 'add -A . && commit' 920 | ``` 921 | 922 | おすすめの設定を挙げておこう: 923 | 924 | | エイリアス | コマンド | 設定方法 | 925 | | --- | --- | --- | 926 | | `git cm` | `git commit` | `git config --global alias.cm commit` | 927 | | `git co` | `git checkout` | `git config --global alias.co checkout` | 928 | | `git ac` | `git add . -A` `git commit` | `git config --global alias.ac '!git add -A && git commit'` | 929 | | `git st` | `git status -sb` | `git config --global alias.st 'status -sb'` | 930 | | `git tags` | `git tag -l` | `git config --global alias.tags 'tag -l'` | 931 | | `git branches` | `git branch -a` | `git config --global alias.branches 'branch -a'` | 932 | | `git cleanup` | `git branch --merged \| grep -v '*' \| xargs git branch -d` | `git config --global alias.cleanup "!git branch --merged \| grep -v '*' \| xargs git branch -d"` | 933 | | `git remotes` | `git remote -v` | `git config --global alias.remotes 'remote -v'` | 934 | | `git lg` | `git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --` | `git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"` | 935 | 936 | #### コマンドの自動修正 937 | 多分今は`git comit`とタイプした場合、以下のような出力を得ることだろう: 938 | 939 | ```bash 940 | $ git comit -m "Message" 941 | # git: 'comit' is not a git command. See 'git --help'. 942 | 943 | # Did you mean this? 944 | # commit 945 | ``` 946 | 947 | これを`comit`とタイプした時に`commit`を実行させたい場合、自動修正を有効にすれば良い: 948 | 949 | ```bash 950 | $ git config --global help.autocorrect 1 951 | ``` 952 | 953 | すると以下のような出力を得るようになるだろう: 954 | 955 | ```bash 956 | $ git comit -m "Message" 957 | # WARNING: You called a Git command named 'comit', which does not exist. 958 | # Continuing under the assumption that you meant 'commit' 959 | # in 0.1 seconds automatically... 960 | ``` 961 | 962 | #### 色設定 963 | Gitの出力をカラフルにするには以下のような設定を加えると良い: 964 | 965 | ```bash 966 | $ git config --global color.ui 1 967 | ``` 968 | 969 | [*Gitの`config`コマンドについてもっと詳しく*](http://git-scm.com/docs/git-config) 970 | 971 | ### Git情報 972 | | Title | Link | 973 | | ----- | ---- | 974 | | Official Git Site | http://git-scm.com/ | 975 | | Official Git Video Tutorials | http://git-scm.com/videos | 976 | | Code School Try Git | http://try.github.com/ | 977 | | Introductory Reference & Tutorial for Git | http://gitref.org/ | 978 | | Official Git Tutorial | http://git-scm.com/docs/gittutorial | 979 | | Everyday Git | http://git-scm.com/docs/everyday | 980 | | Git Immersion | http://gitimmersion.com/ | 981 | | Git for Computer Scientists | http://eagain.net/articles/git-for-computer-scientists/ | 982 | | Git Magic | http://www-cs-students.stanford.edu/~blynn/gitmagic/ | 983 | | GitHub Training Kit | http://training.github.com/kit | 984 | | Git Visualization Playground | http://onlywei.github.io/explain-git-with-d3/#freeplay | 985 | 986 | #### Git Books 987 | | Title | Link | 988 | | ----- | ---- | 989 | | Pragmatic Version Control Using Git | http://www.pragprog.com/titles/tsgit/pragmatic-version-control-using-git | 990 | | Pro Git | http://git-scm.com/book | 991 | | Git Internals PluralSight | https://github.com/pluralsight/git-internals-pdf | 992 | | Git in the Trenches | http://cbx33.github.com/gitt/ | 993 | | Version Control with Git | http://www.amazon.com/Version-Control-Git-collaborative-development/dp/1449316387 | 994 | | Pragmatic Guide to Git | http://www.pragprog.com/titles/pg_git/pragmatic-guide-to-git | 995 | | Git: Version Control for Everyone | http://www.packtpub.com/git-version-control-for-everyone/book | 996 | 997 | ## 訳注 998 | これは[GitHub Cheat Sheet](https://github.com/tiimgreen/github-cheat-sheet)の日本語訳である。 999 | -------------------------------------------------------------------------------- /README.ko.md: -------------------------------------------------------------------------------- 1 | # GitHub 치트 시트 [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 2 | 3 | Git과 GitHub에서 꽤 유용하지만 숨겨져 있는 기능들에 대해 다룹니다. 이 치트 시트는 [Zach Holman](https://github.com/holman)이 Aloha Ruby Conference 2012에서 발표한 [Git과 GitHub의 비밀들](http://confreaks.tv/videos/aloharuby2012-git-and-github-secrets) ([슬라이드](https://speakerdeck.com/holman/git-and-github-secrets))과 WDCNZ 2013에서 발표한 [Git과 GitHub에 대한 더 많은 비밀들](https://vimeo.com/72955426) ([슬라이드](https://speakerdeck.com/holman/more-git-and-github-secrets))에서 영감을 받아 작성되었습니다. 4 | 5 | *단축주소: [`http://git.io/sheet`](http://git.io/sheet)* 6 | 7 | *Read this in other languages: [English](README.md), [한국어](README.ko.md), [日本語](README.ja.md), [简体中文](README.zh-cn.md), [正體中文](README.zh-tw.md).* 8 | 9 | # 목록 10 | 11 | - [GitHub](#github) 12 | - [Ignore Whitespace](#ignore-whitespace) 13 | - [Adjust Tab Space](#adjust-tab-space) 14 | - [Commit History by Author](#commit-history-by-author) 15 | - [Cloning a Repository](#cloning-a-repository) 16 | - [Branch](#branch) 17 | - [Compare all Branches to Another Branch](#compare-all-branches-to-another-branch) 18 | - [Comparing Branches](#comparing-branches) 19 | - [Compare Branches across Forked Repositories](#compare-branches-across-forked-repositories) 20 | - [Gists](#gists) 21 | - [Git.io](#gitio) 22 | - [Keyboard Shortcuts](#keyboard-shortcuts) 23 | - [Line Highlighting in Repositories](#line-highlighting-in-repositories) 24 | - [Closing Issues via Commit Messages](#closing-issues-via-commit-messages) 25 | - [Cross-Link Issues](#cross-link-issues) 26 | - [Locking Conversations](#locking-conversations) 27 | - [CI Status on Pull Requests](#ci-status-on-pull-requests) 28 | - [Filters](#filters) 29 | - [Syntax Highlighting in Markdown Files](#syntax-highlighting-in-markdown-files) 30 | - [Emojis](#emojis) 31 | - [Images/GIFs](#imagesgifs) 32 | - [Embedding Images in GitHub Wiki](#embedding-images-in-github-wiki) 33 | - [Quick Quoting](#quick-quoting) 34 | - [Pasting Clipboard Image to Comments](#pasting-clipboard-image-to-comments) 35 | - [Quick Licensing](#quick-licensing) 36 | - [Task Lists](#task-lists) 37 | - [Task Lists in Markdown Documents](#task-lists-in-markdown-documents) 38 | - [Relative Links](#relative-links) 39 | - [Metadata and Plugin Support for GitHub Pages](#metadata-and-plugin-support-for-github-pages) 40 | - [Viewing YAML Metadata in your Documents](#viewing-yaml-metadata-in-your-documents) 41 | - [Rendering Tabular Data](#rendering-tabular-data) 42 | - [Rendering PDF](#rendering-pdf) 43 | - [Revert a Pull Request](#revert-a-pull-request) 44 | - [Diffs](#diffs) 45 | - [Rendered Prose Diffs](#rendered-prose-diffs) 46 | - [Diffable Maps](#diffable-maps) 47 | - [Expanding Context in Diffs](#expanding-context-in-diffs) 48 | - [Diff or Patch of Pull Request](#diff-or-patch-of-pull-request) 49 | - [Rendering and diffing images](#rendering-and-diffing-images) 50 | - [Hub](#hub) 51 | - [Contribution Guidelines](#contribution-guidelines) 52 | - [CONTRIBUTING file](#contributing-file) 53 | - [ISSUE_TEMPLATE file](#issue_template-file) 54 | - [PULL_REQUEST_TEMPLATE file](#pull_request_template-file) 55 | - [Octicons](#octicons) 56 | - [GitHub Resources](#github-resources) 57 | - [GitHub Talks](#github-talks) 58 | - [Git](#git) 59 | - [Remove All Deleted Files from the Working Tree](#remove-all-deleted-files-from-the-working-tree) 60 | - [Previous Branch](#previous-branch) 61 | - [Stripspace](#stripspace) 62 | - [SSH keys](#ssh-keys) 63 | - [Checking out Pull Requests](#checking-out-pull-requests) 64 | - [Empty Commits](#empty-commits) 65 | - [Styled Git Status](#styled-git-status) 66 | - [Styled Git Log](#styled-git-log) 67 | - [Git Query](#git-query) 68 | - [Git Grep](#git-grep) 69 | - [Merged Branches](#merged-branches) 70 | - [Fixup and Autosquash](#fixup-and-autosquash) 71 | - [Web Server for Browsing Local Repositories](#web-server-for-browsing-local-repositories) 72 | - [Git Configurations](#git-configurations) 73 | - [Aliases](#aliases) 74 | - [Auto-Correct](#auto-correct) 75 | - [Color](#color) 76 | - [Git Resources](#git-resources) 77 | - [Git Books](#git-books) 78 | 79 | ## GitHub 80 | 81 | ### Ignore Whitespace 82 | 83 | `?w=1`를 diff URL에 추가하면 변경된 코드만 볼 수 있도록, 공백만 바뀐 수정을 제거할 수 있습니다. 84 | 85 | ![Diff without whitespace](https://camo.githubusercontent.com/797184940defadec00393e6559b835358a863eeb/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f776869746573706163652e706e67) 86 | 87 | [*GitHub의 비밀을 더 읽어 보세요.*](https://github.com/blog/967-github-secrets) 88 | 89 | ### Adjust Tab Space 90 | 91 | diff나 파일 URL에 `?ts=4`를 덧붙이면 탭 문자의 크기를 기본값인 공백 8개 대신 4개로 보여줍니다. `ts` 뒤의 숫자는 설정에 맞게 변경 하실 수 있습니다. gist나 raw 파일 보기에는 적용 되지 않습니다만, [크롬 확장 프로그램](https://chrome.google.com/webstore/detail/github-tab-size/ofjbgncegkdemndciafljngjbdpfmbkn)이나 으로 자동화 할 수 있습니다. 92 | 93 | 여기에 있는 Go 소스 파일은 `?ts=4`를 붙이기 전에는 이렇습니다. 94 | 95 | ![Before, tab space example](http://i.imgur.com/GIT1Fr0.png) 96 | 97 | 그리고 `?ts=4`를 붙인 다음에는 이렇게 됩니다. 98 | 99 | ![After, tab space example](http://i.imgur.com/70FL4H9.png) 100 | 101 | ### Commit History by Author 102 | 103 | 특정 커미터가 한 모든 커밋을 보고 싶다면 URL에 `?author={user}`를 추가하세요. 104 | 105 | ``` 106 | https://github.com/rails/rails/commits/master?author=dhh 107 | ``` 108 | 109 | ![DHH commit history](http://i.imgur.com/S7AE29b.png) 110 | 111 | [*커밋 뷰간의 차이에 대해 더 읽어보세요.*](https://help.github.com/articles/differences-between-commit-views) 112 | 113 | ### Cloning a Repository 114 | 115 | 저장소를 클론할 때, 맨 뒤의 `.git`은 생략할 수 있습니다. 116 | 117 | ```bash 118 | $ git clone https://github.com/tiimgreen/github-cheat-sheet 119 | ``` 120 | 121 | [*Git `clone` 명령에 대해 더 읽어 보세요.*](http://git-scm.com/docs/git-clone) 122 | 123 | ### Branch 124 | 125 | #### Compare all Branches to Another Branch 126 | 127 | 저장소의 [브랜치](https://github.com/tiimgreen/github-cheat-sheet/branches) 페이지는, 커밋 버튼의 뒤에 있습니다. 128 | 129 | ``` 130 | https://github.com/{user}/{repo}/branches 131 | ``` 132 | 133 | ... 메인 브랜치에 머지되지 않은 모든 브랜치의 리스트를 볼 수 있습니다. 134 | 135 | 여기에서 버튼 클릭으로 비교 페이지에 접속하거나 브랜치를 삭제할 수 있습니다. 136 | 137 | ![Compare branches not merged into master in rails/rails repo - https://github.com/rails/rails/branches](http://i.imgur.com/0FEe30z.png) 138 | 139 | #### Comparing Branches 140 | 141 | GitHub에서 브랜치 비교를 하시려면, URL을 이런 식으로 바꾸세요. 142 | 143 | ``` 144 | https://github.com/{user}/{repo}/compare/{range} 145 | ``` 146 | 147 | `{range}`는 `master...4-1-stable`과 같이 적습니다. 148 | 149 | 예를 들어 150 | 151 | ``` 152 | https://github.com/rails/rails/compare/master...4-1-stable 153 | ``` 154 | 155 | ![Rails branch compare example](http://i.imgur.com/tIRCOsK.png) 156 | 157 | `{range}`는 이렇게 적을 수도 있습니다. 158 | 159 | ``` 160 | https://github.com/rails/rails/compare/master@{1.day.ago}...master 161 | https://github.com/rails/rails/compare/master@{2014-10-04}...master 162 | ``` 163 | 164 | *날짜는 `YYYY-MM-DD` 형식으로 적습니다* 165 | 166 | ![Another compare example](http://i.imgur.com/5dtzESz.png) 167 | 168 | 브랜치는 `diff`나 `patch` 뷰로도 확인할 수 있습니다. 169 | 170 | ``` 171 | https://github.com/rails/rails/compare/master...4-1-stable.diff 172 | https://github.com/rails/rails/compare/master...4-1-stable.patch 173 | ``` 174 | 175 | [*시간으로 커밋을 비교하는 법에 대해 더 읽어 보세요.*](https://help.github.com/articles/comparing-commits-across-time) 176 | 177 | #### Compare branches across forked repositories 178 | 179 | 포크된 저장소 간의 브랜치를 비교하려면 URL을 이렇게 변경하세요. 180 | 181 | ``` 182 | https://github.com/{user}/{repo}/compare/{foreign-user}:{branch}...{own-branch} 183 | ``` 184 | 185 | 예를 들면 186 | 187 | ``` 188 | https://github.com/rails/rails/compare/byroot:idempotent-counter-caches...master 189 | ``` 190 | 191 | ![Forked branch compare](http://i.imgur.com/Q1W6qcB.png) 192 | 193 | ### Gists 194 | 195 | [Gist](https://gist.github.com/)는 본격적인 저장소를 만들지 않고, 작은 코드 조각과 일할 수 있는 쉬운 방법입니다. 196 | 197 | ![Gist](http://i.imgur.com/VkKI1LC.png?1) 198 | 199 | [이렇게](https://gist.github.com/tiimgreen/10545817.pibb) Gist URL 뒤에 `.pibb`를 넣으면 다른 사이트에 첨부할 수 있는 *HTML 온리* 버전을 만들 수 있습니다. 200 | 201 | Gist는 저장소처럼 취급할 수 있고 클론도 됩니다. 202 | 203 | ```bash 204 | $ git clone https://gist.github.com/tiimgreen/10545817 205 | ``` 206 | 207 | ![Gists](http://i.imgur.com/BcFzabp.png) 208 | 209 | 이는 Gists에서도 수정하고 업데이트를 푸시할 수 있다는 의미입니다. 210 | 211 | ```bash 212 | $ git commit 213 | $ git push 214 | Username for 'https://gist.github.com': 215 | Password for 'https://tiimgreen@gist.github.com': 216 | ``` 217 | 218 | 하지만, Gists는 디렉터리를 지원하지 않습니다. 모든 파일은 저장소의 루트에 넣을 필요가 있습니다. 219 | [*Gist를 만드는 법에 대해 더 읽어보세요.*](https://help.github.com/articles/creating-gists) 220 | 221 | ### Git.io 222 | 223 | [Git.io](http://git.io)는 GitHub를 위한 간단한 URL 단축기입니다. 224 | 225 | ![Git.io](http://i.imgur.com/6JUfbcG.png?1) 226 | 227 | Curl으로 순수 HTTP를 통해 사용하실 수도 있습니다. 228 | 229 | ```bash 230 | $ curl -i http://git.io -F "url=https://github.com/..." 231 | HTTP/1.1 201 Created 232 | Location: http://git.io/abc123 233 | 234 | $ curl -i http://git.io/abc123 235 | HTTP/1.1 302 Found 236 | Location: https://github.com/... 237 | ``` 238 | 239 | [*Git.io에 대해 더 읽어 보세요.*](https://github.com/blog/985-git-io-github-url-shortener) 240 | 241 | ### Keyboard Shortcuts 242 | 243 | 저장소 페이지에서 단축키를 사용하면 쉽게 이동할 수 있습니다. 244 | 245 | - `t`를 누르면 파일 탐색 페이지로 이동합니다. 246 | - `w`를 누르면 브랜치 선택 페이지로 이동합니다. 247 | - `s`를 누르면 현재 저장소의 검색창으로 포커스가 이동합니다. 백스페이스를 누르면 채워져 있는 "This repository"를 지워 GitHub 전체에서 검색할 수 있게 됩니다. 248 | - `l`을 누르면 이슈의 라벨을 수정할 수 있습니다. 249 | - __파일을 보고 있을 때__ (예를 들어 `https://github.com/tiimgreen/github-cheat-sheet/blob/master/README.md`) `y`를 누르면 URL을 지금 보고 있는 페이지를 사실상 고정하도록 합니다. 코드가 바뀐다고 해도 이번에 본 내용을 다시 볼 수 있습니다. 250 | 251 | 지금 페이지에서 쓸 수 있는 모든 단축키를 보시려면 `?`를 누르세요. 252 | 253 | ![Keyboard shortcuts](http://i.imgur.com/y5ZfNEm.png) 254 | 255 | [*사용할 수 있는 검색 문법에 대해 더 읽어 보세요.*](https://help.github.com/articles/search-syntax/) 256 | 257 | ### Line Highlighting in Repos 258 | 259 | 코드 파일 URL의 끝에 `#L52`를 추가하거나 줄 번호를 클릭하면 그 줄 번호를 하이라이트합니다. 260 | 261 | `#L53-L60`처럼 범위 지정도 가능합니다. 범위를 지정하려면 `shift`키를 누른 채 두 라인을 클릭하면 됩니다. 262 | 263 | ``` 264 | https://github.com/rails/rails/blob/master/activemodel/lib/active_model.rb#L53-L60 265 | ``` 266 | 267 | ![Line Highlighting](http://i.imgur.com/8AhjrCz.png) 268 | 269 | ### Closing Issues with Commits 270 | 271 | 어떤 커밋이 이슈를 고쳤다면, `fix/fixes/fixed`, `close/closes/closed`, `resolve/resolves/resolved`를 키워드로 해당 이슈가 마스터 브랜치에 커밋 될 때 닫을 수 있습니다. 272 | 273 | ```bash 274 | $ git commit -m "Fix screwup, fixes #12" 275 | ``` 276 | 277 | 이렇게 하면 이슈를 닫고 클로징 커밋으로 참조하게 합니다. 278 | 279 | ![Closing Repo](http://i.imgur.com/Uh1gZdx.png) 280 | 281 | [*커밋 메시지로 이슈 닫기에 대해 더 읽어 보세요.*](https://help.github.com/articles/closing-issues-via-commit-messages) 282 | 283 | ### Cross-Link Issues 284 | 285 | 같은 저장소의 다른 이슈를 링크하기 원한다면, `#` 뒤에 이슈 번호만 입력하시면 자동으로 링크됩니다. 286 | 287 | 다른 저장소의 이슈를 링크하고 싶다면 `{user}/{repo}#이슈_번호`로 할 수 있습니다. (예 `tiimgreen/toc#12`) 288 | 289 | ![Cross-Link Issues](https://camo.githubusercontent.com/447e39ab8d96b553cadc8d31799100190df230a8/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f7265666572656e6365732e706e67) 290 | 291 | ### Locking Conversations 292 | 293 | 풀 리퀘스트와 이슈는 저장소의 주인이나 협업자가 잠글 수 있습니다. 294 | 295 | ![Lock conversation](https://cloud.githubusercontent.com/assets/2723/3221693/bf54dd44-f00d-11e3-8eb6-bb51e825bc2c.png) 296 | 297 | 이는 프로젝트의 협업자가 아닌 사람은 더 이상 댓글을 달 수 없게 된다는 말입니다. 298 | 299 | ![Comments locked](https://cloud.githubusercontent.com/assets/2723/3221775/d6e513b0-f00e-11e3-9721-2131cb37c906.png) 300 | 301 | [*대화 잠그기에 대해 더 읽어 보세요.*](https://github.com/blog/1847-locking-conversations) 302 | 303 | ### CI Status on Pull Requests 304 | 305 | 정확히 설정되었다면, 풀 리퀘스트를 받거나 풀 리퀘스트에 새로운 커밋을 할 때마다, [Travis CI](https://travis-ci.org/)가 풀 리퀘스트를 빌드 할 것입니다. [Travis CI 시작하기](http://docs.travis-ci.com/user/getting-started/)를 좀 더 읽어보세요. 306 | 307 | [![Travis CI status](https://cloud.githubusercontent.com/assets/1687642/2700187/3a88838c-c410-11e3-9a46-e65e2a0458cd.png)](https://github.com/octokit/octokit.rb/pull/452) 308 | 309 | [*커밋 상태 API에 대해 좀 더 읽어보세요.*](https://github.com/blog/1227-commit-status-api) 310 | 311 | ### Filters 312 | 313 | 이슈, 풀 리퀘스트 둘 다 유저 인터페이스에서 필터링이 가능합니다. 314 | 315 | 레일스 저장소 에서, "activerecord" 라벨을 316 | 선택하여 다음 필터를 만들 수 있습니다. 317 | 318 | `is:issue label:activerecord` 319 | 320 | 하지만, activerecord 라벨이 없는 모든 이슈를 찾을 수도 있습니다. 321 | 322 | `is:issue -label:activerecord` 323 | 324 | 덧붙여, 풀 리퀘스트에도 동작합니다. 325 | 326 | `is:pr -label:activerecord` 327 | 328 | GitHub는 열리거나 닫힌 이슈와 풀 리퀘스트를 위한 탭이 있습니다만 머지된 329 | 풀 리퀘스트도 볼 수 있습니다. 다음 필터를 입력하기만 하면 됩니다. 330 | 331 | `is:merged` 332 | 333 | [*이슈 검색에 대해 좀 더 읽어보세요.*](https://help.github.com/articles/searching-issues) 334 | 335 | 마지막으로 이제 상태 API의 상태에 의한 필터도 가능해졌습니다. 336 | 337 | 성공 상태의 풀 리퀘스트는 이렇게 검색합니다. 338 | 339 | `status:success` 340 | 341 | [*상태 API 검색에 대해 좀 더 읽어보세요.*](https://github.com/blog/2014-filter-pull-requests-by-status) 342 | 343 | ### Syntax Highlighting in Markdown Files 344 | 345 | 마크다운에서 예를 들어, 루비 코드를 신텍스 하이라이트 하려면 이렇게 합니다. 346 | 347 | ```ruby 348 | require 'tabbit' 349 | table = Tabbit.new('Name', 'Email') 350 | table.add_row('Tim Green', 'tiimgreen@gmail.com') 351 | puts table.to_s 352 | ``` 353 | 354 | 이렇게 보입니다. 355 | 356 | ```ruby 357 | require 'tabbit' 358 | table = Tabbit.new('Name', 'Email') 359 | table.add_row('Tim Green', 'tiimgreen@gmail.com') 360 | puts table.to_s 361 | ``` 362 | 363 | GitHub는 [Linguist](https://github.com/github/linguist)를 사용해 언어를 감지하고 신택스를 하이라이트합니다. [언어 YAML 파일](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml)을 정독하시면 어떤 키워드가 유효한지 확인하실 수 있습니다. 364 | 365 | [*GitHub Flavored 마크다운에 대해 더 읽어 보세요.*](https://help.github.com/articles/github-flavored-markdown) 366 | 367 | ### Emojis 368 | 369 | 에모지는 풀 리퀘스트, 이슈, 커밋 메시지, 저장소 설명 등에 `:에모지의_이름:`으로 넣을 수 있습니다. 370 | 371 | GitHub에서 사용 가능한 에모지의 전 목록은 [emoji-cheat-sheet.com](http://www.emoji-cheat-sheet.com/)나 [scotch-io/All-GitHub-Emoji-Icons](https://github.com/scotch-io/All-GitHub-Emoji-Icons)에서 확인하실 수 있습니다. 372 | 편리한 에모지 검색 엔진은 [emoji.muan.co](http://emoji.muan.co/)에 있습니다. 373 | 374 | GitHub에서 많이 사용하는 에모지 탑 5위는 이렇습니다. 375 | 376 | 1. `:shipit:` 377 | 2. `:sparkles:` 378 | 3. `:-1:` 379 | 4. `:+1:` 380 | 5. `:clap:` 381 | 382 | ### Images/GIFs 383 | 384 | 댓글이나 README 등에 이미지와 GIF를 넣을 수 있습니다. 385 | 386 | ``` 387 | ![Alt Text](http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif) 388 | ``` 389 | 390 | 저장소에 있는 이미지는 직접 불러서 사용할 수 있습니다. 391 | 392 | ``` 393 | ![Alt Text](https://github.com/{user}/{repo}/raw/master/path/to/image.gif) 394 | ``` 395 | 396 | ![Peter don't care](http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif) 397 | 398 | 모든 이미지는 GitHub에서 캐시합니다. 그래서 호스트가 죽어도 이미지는 여전히 남습니다. 399 | 400 | #### Embedding Images in GitHub Wiki 401 | 402 | 이미지를 위키 페이지에 넣는 방법은 여럿 있습니다. 위에 보이는 일반 마크다운 문법도 있지만, 이미지에 높이와 넓이를 지정할 수 있는 문법도 있습니다. 403 | 404 | ```markdown 405 | [[ http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif | height = 100px ]] 406 | ``` 407 | 408 | 이렇게 보입니다. 409 | 410 | ![Just a screenshot](http://i.imgur.com/J5bMf7S.png) 411 | 412 | ### Quick Quoting 413 | 414 | 스레드에 답글을 달 때 전에 누가 말한 어떤 내용을 인용하고 싶다면, 텍스트를 하이라이트하고 `r`을 누르세요. 이렇게 하면 내용을 텍스트 박스에 인용 포맷으로 복사해 줍니다. 415 | 416 | ![Quick Quote](https://f.cloud.github.com/assets/296432/124483/b0fa6204-6ef0-11e2-83c3-256c37fa7abc.gif) 417 | 418 | [*빠른 인용에 대해 더 읽어 보세요.*](https://github.com/blog/1399-quick-quotes) 419 | 420 | ### Pasting Clipboard Image to Comments 421 | 422 | _(크롬에서만 동작합니다)_ 423 | 424 | 스크린샷을 찍고 클립보드에 복사한 경우 (mac: `cmd-ctrl-shift-4`), 간단히 이미지를 댓글 영역에 붙여넣을(`cmd-v / ctrl-v`) 수 있고 이는 자동으로 GitHub에 업로드 됩니다. 425 | 426 | ![Pasting Clipboard Image to Comments](https://cloud.githubusercontent.com/assets/39191/5794265/39c9b65a-9f1b-11e4-9bc7-04e41f59ea5f.png) 427 | 428 | [*issue attachments에 대해 더 읽어 보세요.*](https://help.github.com/articles/issue-attachments) 429 | 430 | ### Quick Licensing 431 | 432 | 저장소를 만들 때, GitHub는 만들어진 저작권을 추가할 수 있는 옵션을 제공합니다. 433 | 434 | ![License](http://i.imgur.com/Chqj4Fg.png) 435 | 436 | 이미 있는 저장소에도 웹 인터페이스에서 새 파일을 만들어 추가할 수 있습니다. 437 | 이름에 `LICENSE`를 입력하면 옵션으로 템플릿을 사용할 수 있습니다. 438 | 439 | ![License](http://i.imgur.com/fTjQict.png) 440 | 441 | `.gitignore`에도 똑같이 적용됩니다. 442 | 443 | [*오픈 소스 저작권에 대해 더 읽어 보세요.*](https://help.github.com/articles/open-source-licensing) 444 | 445 | ### Task Lists 446 | 447 | 이슈와 풀 리퀘스트에서 아래의 문법으로 체크박스를 넣을 수 있습니다.(스페이스에 주의하세요.) 448 | 449 | ``` 450 | - [ ] Be awesome 451 | - [ ] Prepare dinner 452 | - [ ] Research recipe 453 | - [ ] Buy ingredients 454 | - [ ] Cook recipe 455 | - [ ] Sleep 456 | ``` 457 | 458 | ![Task List](http://i.imgur.com/jJBXhsY.png) 459 | 460 | 체크박스를 클릭하면, 순수 마크다운에서 갱신이 이루어집니다. 461 | 462 | ``` 463 | - [x] Be awesome 464 | - [ ] Prepare dinner 465 | - [x] Research recipe 466 | - [x] Buy ingredients 467 | - [ ] Cook recipe 468 | - [ ] Sleep 469 | ``` 470 | 471 | [*할 일 목록에 대해 더 읽어 보세요.*](https://help.github.com/articles/writing-on-github#task-lists) 472 | 473 | #### Task Lists in Markdown Documents 474 | 475 | 이제 마크다운 문서에서 **읽기 전용** 체크리스트를 넣을 수 있습니다. 476 | 477 | ``` 478 | - [ ] Mercury 479 | - [x] Venus 480 | - [x] Earth 481 | - [x] Moon 482 | - [x] Mars 483 | - [ ] Deimos 484 | - [ ] Phobos 485 | ``` 486 | 487 | - [ ] Mercury 488 | - [x] Venus 489 | - [x] Earth 490 | - [x] Moon 491 | - [x] Mars 492 | - [ ] Deimos 493 | - [ ] Phobos 494 | 495 | [*마크다운 문서에서의 할 일 목록에 대해 더 읽어 보세요.*](https://github.com/blog/1825-task-lists-in-all-markdown-documents) 496 | 497 | ### Relative Links 498 | 499 | 상대 경로 링크는 마크다운 파일이 내부 콘텐츠로 링크될 때 추천합니다. 500 | 501 | ```markdown 502 | [Link to a header](#awesome-section) 503 | [Link to a file](docs/readme) 504 | ``` 505 | 506 | 절대 경로 링크는 URL이 변경 될 때마다 변경해야 합니다. (예를 들어 저장소 이름 변경, 아이디 변경, 프로젝트 포크) 507 | 상대 경로 링크를 사용하면 문서를 쉽게 스스로 독립적으로 만들 수 있습니다. 508 | 509 | [*상대 경로 링크에 대해 더 읽어 보세요.*](https://help.github.com/articles/relative-links-in-readmes) 510 | 511 | ### Metadata and Plugin Support for GitHub Pages 512 | 513 | 지킬로 작성된 페이지와 포스트에서, 저장소 정보는 예를 들어 `{{ site.github.project_title }}`처럼 `site.github` 이름 공간으로 사용하고 표시할 수 있습니다. 514 | 515 | Jemoji와 jekyll-mentions 플러그인은 GitHub.com에서처럼 [emoji](#emojis)와 [@mentions](https://github.com/blog/821)를 지킬 포스트와 페이지에서 사용하게 합니다. 516 | 517 | [*저장소 메타 데이터와 GitHub 페이지의 플러그인 지원에 대해 더 읽어 보세요.*](https://github.com/blog/1797-repository-metadata-and-plugin-support-for-github-pages) 518 | 519 | ### Viewing YAML Metadata in your Documents 520 | 521 | [Jekyll](http://jekyllrb.com/)이나 [GitHub Pages](http://pages.github.com/) 같은 많은 블로그에서 포스트의 처음에 YAML 포멧의 메타데이터를 필요로 합니다. GitHub는 이 메타 정보를 읽기 편하게 테이블로 표시해 줍니다. 522 | 523 | ![YAML metadata](https://camo.githubusercontent.com/47245aa16728e242f74a9a324ce0d24c0b916075/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f36343035302f313232383236372f65303439643063362d323761302d313165332d396464382d6131636432323539393334342e706e67) 524 | 525 | [*문서에서 YAML 메타데이터 보기에 대해 더 읽어 보세요.*](https://github.com/blog/1647-viewing-yaml-metadata-in-your-documents) 526 | 527 | ### Rendering Tabular Data 528 | 529 | GitHub는 `.csv`(comma-separated)와 `.tsv`(tab-separated) 파일에 대해 표(tabular) 데이터 보기를 지원합니다. 530 | 531 | ![Tabular data](https://camo.githubusercontent.com/1b6dd0157ffb45d9939abf14233a0cb13b3b4dfe/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3238323735392f3937363436322f33323038336463652d303638642d313165332d393262322d3566323863313061353035392e706e67) 532 | 533 | [*표 데이터 표시에 대해 더 읽어 보세요.*](https://github.com/blog/1601-see-your-csvs) 534 | 535 | ### Rendering PDF 536 | 537 | GitHub에서 PDF를 렌더할 수 있습니다. 538 | 539 | ![PDF](https://cloud.githubusercontent.com/assets/1000669/7492902/f8493160-f42e-11e4-8cea-1cb4f02757e7.png) 540 | 541 | [*PDF 렌더링에 대해 더 읽어 보세요.*](https://github.com/blog/1974-pdf-viewing) 542 | 543 | ### Revert a Pull Request 544 | 545 | 풀 리퀘스트가 머지된 후에, 아무 도움이 안되거나 머지가 잘못된 결정이었다는 걸 546 | 눈치 챌 때가 있습니다. 547 | 548 | 풀 리퀘스트 페이지의 커밋의 오른쪽에 있는 **Revert** 버튼을 클릭하면 이 풀 리퀘스트를 되돌리는 풀 리퀘스트를 만들어 되돌릴 수 있습니다. 549 | 550 | ![Revert button](https://camo.githubusercontent.com/0d3350caf2bb1cba53123ffeafc00ca702b1b164/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f68656c702f70756c6c5f72657175657374732f7265766572742d70756c6c2d726571756573742d6c696e6b2e706e67) 551 | 552 | [*풀 리퀘스트 되돌리기에 대해 더 읽어 보세요.*](https://github.com/blog/1857-introducing-the-revert-button) 553 | 554 | ### Diffs 555 | 556 | #### Rendered Prose Diffs 557 | 558 | GitHub에서 지원하는 산문(prose) 파일(예를 들어 Markdown)이 있는 커밋과 풀 리퀘스트에서는 *source*와 *rendered* 뷰 기능을 사용할 수 있습니다. 559 | 560 | ![Source / Rendered view](https://github-images.s3.amazonaws.com/help/repository/rendered_prose_diff.png) 561 | 562 | "rendered" 버튼을 클릭하시면 렌더된 문서에서 변경을 확인하실 수 있습니다. 렌더된 산문(prose) 뷰는 문장을 추가, 삭제, 변경했을 때 유용합니다. 563 | 564 | ![Rendered Prose Diffs](https://f.cloud.github.com/assets/17715/2003056/3997edb4-862b-11e3-90be-5e9586edecd7.png) 565 | 566 | [*렌더된 산문(prose) diff에 대해 더 읽어 보세요.*](https://github.com/blog/1784-rendered-prose-diffs) 567 | 568 | #### Diffable Maps 569 | 570 | 지오데이터가 포함된 커밋이나 풀 리퀘스트를 볼 때마다 GitHub는 무엇이 변경 되었는지 시각적으로 보여줍니다. 571 | 572 | [![Diffable Maps](https://f.cloud.github.com/assets/282759/2090660/63f2e45a-8e97-11e3-9d8b-d4c8078b004e.gif)](https://github.com/benbalter/congressional-districts/commit/2233c76ca5bb059582d796f053775d8859198ec5) 573 | 574 | [*diff 가능한 맵에 대해 더 읽어 보세요.*](https://github.com/blog/1772-diffable-more-customizable-maps) 575 | 576 | #### Expanding Context in Diffs 577 | 578 | diff의 닫아둔 곳의 *펼침* 버튼을 클릭하면, 문맥을 더 볼 수 있습니다. 전체 파일을 표시할 때까지 계속 *펼칠* 수 있으며, GitHub에서 diff가 표시되는 장소라면 어디서든 사용가능합니다. 579 | 580 | ![Expanding Context in Diffs](https://f.cloud.github.com/assets/22635/1610539/863c1f64-5584-11e3-82bf-151b406a272f.gif) 581 | 582 | [*diff에서의 문맥 확장에 대해 더 읽어 보세요.*](https://github.com/blog/1705-expanding-context-in-diffs) 583 | 584 | #### Diff or Patch of Pull Request 585 | 586 | URL 뒤에 `.diff`나 `.patch`를 붙이면 풀 리퀘스트의 diff를 얻을 수 있습니다. 587 | 예를 들면 588 | 589 | ``` 590 | https://github.com/tiimgreen/github-cheat-sheet/pull/15 591 | https://github.com/tiimgreen/github-cheat-sheet/pull/15.diff 592 | https://github.com/tiimgreen/github-cheat-sheet/pull/15.patch 593 | ``` 594 | 595 | `.diff` 확장자는 이런 내용의 평범한(plain) 텍스트를 줍니다. 596 | 597 | ``` 598 | diff --git a/README.md b/README.md 599 | index 88fcf69..8614873 100644 600 | --- a/README.md 601 | +++ b/README.md 602 | @@ -28,6 +28,7 @@ All the hidden and not hidden features of Git and GitHub. This cheat sheet was i 603 | - [Merged Branches](#merged-branches) 604 | - [Quick Licensing](#quick-licensing) 605 | - [TODO Lists](#todo-lists) 606 | +- [Relative Links](#relative-links) 607 | - [.gitconfig Recommendations](#gitconfig-recommendations) 608 | - [Aliases](#aliases) 609 | - [Auto-correct](#auto-correct) 610 | @@ -381,6 +382,19 @@ When they are clicked, they will be updated in the pure Markdown: 611 | - [ ] Sleep 612 | 613 | (...) 614 | ``` 615 | 616 | #### Rendering and diffing images 617 | 618 | GitHub는 PNG, JPG, GIF, PSD를 포함한 여러 일반적인 이미지 형식을 표시할 수 있습니다. 추가적으로 이미지 형식의 diff를 표시하는 여러 방법을 제공합니다. 619 | 620 | [![Diffable PSD](https://cloud.githubusercontent.com/assets/2546/3165594/55f2798a-eb56-11e3-92e7-b79ad791a697.gif)](https://github.com/blog/1845-psd-viewing-diffing 621 | 622 | [*이미지 diff에 대해 더 읽어 보세요.*](https://help.github.com/articles/rendering-and-diffing-images) 623 | 624 | ### Hub 625 | 626 | [Hub](https://github.com/github/hub)는 GitHub를 좀 더 쉽게 사용할 수 있도록 추가 기능 및 명령을 제공하는 커맨드 라인 Git 래퍼입니다. 627 | 628 | 이렇게 할 수 있습니다. 629 | 630 | ```bash 631 | $ hub clone tiimgreen/toc 632 | ``` 633 | 634 | [*Hub가 제공하는 더 멋진 기능들을 확인해 보세요.*](https://github.com/github/hub#commands) 635 | 636 | ### Contribution Guidelines 637 | 638 | GitHub는 프로젝트에 기여하는 사용자를 위한 세 가지 각기 다른 파일을 지원합니다. 639 | 이 파일은 저장소의 제일 위나 그 아래의 `.github` 디렉터리에 위치할 수 있습니다. 640 | 641 | ### CONTRIBUTING File 642 | 643 | 저장소의 제일 위나 그 아래의 `.github` 디렉터리에 `CONTRIBUTING`이나 `CONTRIBUTING.md` 파일을 넣어두면 기여자가 이슈를 만들거나 풀 리퀘스트를 만들 때 링크로 보여줍니다. 644 | 645 | ![Contributing Guidelines](https://camo.githubusercontent.com/71995d6b0e620a9ef1ded00a04498241c69dd1bf/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f736b697463682f6973737565732d32303132303931332d3136323533392e6a7067) 646 | 647 | [*기여하기에 대해 더 읽어 보세요.*](https://github.com/blog/1184-contributing-guidelines) 648 | 649 | ### ISSUE_TEMPLATE file 650 | 651 | 프로젝트의 새로운 이슈에 사용될 템플릿을 지정할 수 있습니다. 사용자가 새 이슈를 생성하면 이슈 창이 이 파일의 내용으로 채워집니다. 저장소의 제일 위나 그 아래의 `.github` 디렉터리에 `ISSUE_TEMPLATE`이나 `ISSUE_TEMPLATE.md` 파일을 넣어 두세요. 652 | 653 | [*이슈 템플릿에 대해 더 읽어 보세요.*](https://github.com/blog/2111-issue-and-pull-request-templates) 654 | 655 | [이슈 템플릿 파일 생성기](https://www.talater.com/open-source-templates/) 656 | 657 | ![GitHub Issue template](https://cloud.githubusercontent.com/assets/25792/13120859/733479fe-d564-11e5-8a1f-a03f95072f7a.png) 658 | 659 | ### PULL_REQUEST_TEMPLATE file 660 | 661 | 프로젝트의 새로운 풀 리퀘스트에 사용될 템플릿을 지정할 수 있습니다. 사용자가 새 풀 리퀘스트를 생성하면 텍스트 영역이 이 파일의 내용으로 채워집니다. 저장소의 제일 위나 `.github` 디렉터리에 `PULL_REQUEST_TEMPLATE`이나 `PULL_REQUEST_TEMPLATE.md` 파일을 넣어 두세요. 662 | 663 | [*풀 리퀘스트 템플릿에 대해 더 읽어 보세요.*](https://github.com/blog/2111-issue-and-pull-request-templates) 664 | 665 | [풀 리퀘스트 템플릿 파일 생성기](https://www.talater.com/open-source-templates/) 666 | 667 | ### Octicons 668 | 669 | GitHub 아이콘(옥티콘)이 이제 오픈소스가 되었습니다. 670 | 671 | ![Octicons](https://og.github.com/octicons/octicons@1200x630.png) 672 | 673 | [*GitHub 옥티콘에 대해 더 읽어보세요.*](https://octicons.github.com) 674 | 675 | ### GitHub Resources 676 | 677 | | Title | Link | 678 | | ----- | ---- | 679 | | GitHub Explore | https://github.com/explore | 680 | | GitHub Blog | https://github.com/blog | 681 | | GitHub Help | https://help.github.com/ | 682 | | GitHub Training | https://training.github.com/ | 683 | | GitHub Developer | https://developer.github.com/ | 684 | | GitHub Education (Free Micro Account and other stuff for students) | https://education.github.com/ | 685 | 686 | #### GitHub Talks 687 | 688 | | Title | Link | 689 | | ----- | ---- | 690 | | How GitHub Uses GitHub to Build GitHub | https://www.youtube.com/watch?v=qyz3jkOBbQY | 691 | | Introduction to Git with Scott Chacon of GitHub | https://www.youtube.com/watch?v=ZDR433b0HJY | 692 | | How GitHub No Longer Works | https://www.youtube.com/watch?v=gXD1ITW7iZI | 693 | | Git and GitHub Secrets | https://www.youtube.com/watch?v=Foz9yvMkvlA | 694 | | More Git and GitHub Secrets | https://www.youtube.com/watch?v=p50xsL-iVgU | 695 | 696 | ## Git 697 | 698 | ### Remove All Deleted Files from the Working Tree 699 | 700 | `/bin/rm`을 사용해 대량의 파일을 지울 때, 하나씩 제거할 필요 없이 밑의 명령어를 사용해 작업 디렉터리와 인덱스에서 지울 수 있습니다. 701 | 702 | ```bash 703 | $ git rm $(git ls-files -d) 704 | ``` 705 | 706 | 예를 들어 707 | 708 | ```bash 709 | $ git status 710 | On branch master 711 | Changes not staged for commit: 712 | deleted: a 713 | deleted: c 714 | 715 | $ git rm $(git ls-files -d) 716 | rm 'a' 717 | rm 'c' 718 | 719 | $ git status 720 | On branch master 721 | Changes to be committed: 722 | deleted: a 723 | deleted: c 724 | ``` 725 | 726 | ### Previous Branch 727 | 728 | Git에서 이전 브랜치로 돌아가는 건 이렇게 할 수 있습니다. 729 | 730 | ```bash 731 | $ git checkout - 732 | # Switched to branch 'master' 733 | 734 | $ git checkout - 735 | # Switched to branch 'next' 736 | 737 | $ git checkout - 738 | # Switched to branch 'master' 739 | ``` 740 | 741 | [*Git 브랜치에 대해 더 읽어 보세요.*](http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging) 742 | 743 | ### Stripspace 744 | 745 | Git Stripspace는 이런 일을 합니다. 746 | 747 | - 줄 끝의 공백을 제거 748 | - 빈줄을 줄임 749 | - 파일 끝에 빈 줄을 추가 750 | 751 | 커맨드를 실행 할 때 파일을 반드시 이런식으로 넘겨줘야 합니다. 752 | 753 | ```bash 754 | $ git stripspace < README.md 755 | ``` 756 | 757 | [*Git `stripspace` 커맨드에 대해 더 읽어 보세요.*](http://git-scm.com/docs/git-stripspace) 758 | 759 | ### SSH keys 760 | 761 | 아래 주소를 방문하면 공개 ssh 키의 목록을 일반 텍스트 형식으로 볼 수 있습니다. 762 | 763 | ``` 764 | https://github.com/{user}.keys 765 | ``` 766 | 767 | 예: [https://github.com/tiimgreen.keys](https://github.com/tiimgreen.keys) 768 | 769 | [*공개 ssh 키 접근에 대해 더 읽어 보세요.*](https://changelog.com/github-exposes-public-ssh-keys-for-its-users/) 770 | 771 | ### Checking out Pull Requests 772 | 773 | 풀 리퀘스트는 GitHub 저장소에서 사용하는 특별한 브랜치로 여러 방법으로 로컬로 774 | 가져올 수 있습니다. 775 | 776 | 빠르게 `diff`나 `merge`를 하기 위해 특정 풀 리퀘스트를 임시로 `FETCH_HEAD`로 777 | 가져오려면 이렇게 합니다. 778 | 779 | ```bash 780 | $ git fetch origin refs/pull/[PR-Number]/head 781 | ``` 782 | 783 | 모든 풀 리퀘스트 브랜치를 refspec에 의한 로컬 리모트 브랜치로 받을 수도 784 | 있습니다. 785 | 786 | ```bash 787 | $ git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*' 788 | ``` 789 | 790 | 밑의 줄들을 저장소의 `.git/config`에 추가하여, 리모트의 풀 리퀘스트를 자동으로 791 | 가져오게도 할 수 있습니다. 792 | 793 | ``` 794 | [remote "origin"] 795 | fetch = +refs/heads/*:refs/remotes/origin/* 796 | url = git@github.com:tiimgreen/github-cheat-sheet.git 797 | ``` 798 | 799 | ``` 800 | [remote "origin"] 801 | fetch = +refs/heads/*:refs/remotes/origin/* 802 | url = git@github.com:tiimgreen/github-cheat-sheet.git 803 | fetch = +refs/pull/*/head:refs/remotes/origin/pr/* 804 | ``` 805 | 806 | 포크 기반의 풀 리퀘스트 기여를 위해, 풀 리퀘스트의 리모트 브랜치를 `checkout`해 807 | 로컬 브랜치를 만드는 것은 유용합니다. 808 | 809 | ```bash 810 | $ git checkout pr/42 pr-42 811 | ``` 812 | 813 | 여러 저장소를 다루어야 한다면, 전역 Git 설정에서 풀 리퀘스트를 받을(fetching) 수 있도록 설정 할 수도 있습니다. 814 | 815 | ```bash 816 | git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*" 817 | ``` 818 | 819 | 이렇게 하면 모든 저장소에서 짧은 명령어를 사용 할 수 있습니다. 820 | 821 | ```bash 822 | git fetch origin 823 | ``` 824 | 825 | ```bash 826 | git checkout pr/42 827 | ``` 828 | 829 | [*풀 리퀘스트를 로컬로 체크아웃 하는 방법에 대해 더 읽어 보세요.*](https://help.github.com/articles/checking-out-pull-requests-locally) 830 | 831 | ### Empty Commits 832 | 833 | `--allow-empty`를 추가하시면 코드의 변경 없이 커밋을 넣을 수 있습니다. 834 | 835 | ```bash 836 | $ git commit -m "Big-ass commit" --allow-empty 837 | ``` 838 | 839 | 있을 법한 사용법에는 이런 것들이 있습니다. 840 | 841 | - 한 뭉치의 일을 시작하기 전에 주석으로 사용 842 | - 코드와 관련없는 프로젝트 수정을 할때 주석으로 사용 843 | - 저장소를 사용하는 사람과의 대화 844 | - 저장소의 첫 커밋으로 사용 `git commit -m "Initial commit" --allow-empty` 845 | 846 | ### Styled Git Status 847 | 848 | ```bash 849 | $ git status 850 | ``` 851 | 852 | ![git status](http://i.imgur.com/qjPyvXb.png) 853 | 854 | `-sb`를 추가하면 855 | 856 | ```bash 857 | $ git status -sb 858 | ``` 859 | 860 | 이렇게 바뀝니다. 861 | 862 | ![git status -sb](http://i.imgur.com/K0OY3nm.png) 863 | 864 | [*Git `status` 커맨드에 대해 더 읽어 보세요.*](http://git-scm.com/docs/git-status) 865 | 866 | ### Styled Git Log 867 | 868 | 이 명령을 실행하면 869 | 870 | ```bash 871 | $ git log --all --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative 872 | ``` 873 | 874 | 이렇게 보입니다. 875 | 876 | ![git log --all --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative](http://i.imgur.com/58eOtkW.png) 877 | 878 | [Palesz](http://stackoverflow.com/users/88355/palesz) 님 고맙습니다. 879 | 880 | NOTE: 이 명령을 알리아스(단축 명령)로 넣을 수 있습니다. [여기](#aliases)의 소개를 보세요. 881 | 882 | [*Git `log` 커맨드에 대해 더 읽어 보세요.*](http://git-scm.com/docs/git-log) 883 | 884 | ### Git Query 885 | 886 | Git 쿼리는 모든 이전 커밋 메시지에서 검색해 가장 최근의 쿼리에 맞는 커밋을 찾아줍니다. 887 | 888 | ```bash 889 | $ git show :/query 890 | ``` 891 | 892 | `query`에는 검색하고 싶은 말을 (대소문자를 구분해) 넣으세요. 주어진 검색어가 있는 가장 마지막 커밋을 표시하고 변경된 라인을 보여줍니다. 893 | 894 | ```bash 895 | $ git show :/typo 896 | ``` 897 | 898 | ![git show :/query](http://i.imgur.com/icaGiNt.png) 899 | 900 | *나오려면 `q`를 누르세요.* 901 | 902 | ### Git Grep 903 | 904 | Git Grep은 패턴과 일치하는 줄의 목록을 반환합니다. 905 | 906 | 다음 명령을 실행해 보세요. 907 | 908 | ```bash 909 | $ git grep aliases 910 | ``` 911 | 912 | *aliases* 문자열이 포함된 모든 파일을 보여줍니다. 913 | 914 | ![git grep aliases](http://i.imgur.com/DL2zpQ9.png) 915 | 916 | *나오려면 `q`를 누르세요.* 917 | 918 | 여러 플래그를 이용해서 좀 더 복잡한 검색을 할 수 있습니다. 예를 들면, 919 | 920 | * `-e` 다음 파라미터는 패턴 (e.g. regex) 921 | * `--and`, `--or`, `--not`으로 여러 패턴을 조합 922 | 923 | 이렇게 사용할 수 있습니다. 924 | ```bash 925 | $ git grep -e pattern --and -e anotherpattern 926 | ``` 927 | 928 | [*Git `grep` 커맨드에 대해 더 읽어 보세요.*](http://git-scm.com/docs/git-grep) 929 | 930 | ### Merged Branches 931 | 932 | ```bash 933 | $ git branch --merged 934 | ``` 935 | 936 | 이 명령어는 현재 브랜치에 머지된 모든 브랜치의 목록을 보여줍니다. 937 | 938 | 거꾸로 939 | 940 | ```bash 941 | $ git branch --no-merged 942 | ``` 943 | 944 | 이 명령어는 현재 브랜치에 머지되지 않은 브랜치의 목록을 보여줍니다. 945 | 946 | [*Git `branch` 커맨드에 대해 더 읽어 보세요.*](http://git-scm.com/docs/git-branch) 947 | 948 | ### Fixup and Autosquash 949 | 950 | 이전(HEAD의 한 개 이상 전의) 커밋에 잘못된 부분이 있다면, 예를 들어 `abcde`라면, 951 | 문제를 수정하고 밑의 커맨드를 입력해 고칠 수 있습니다. 952 | 953 | ```bash 954 | $ git commit --fixup=abcde 955 | $ git rebase abcde^ --autosquash -i 956 | ``` 957 | [*Git `commit` 커맨드에 대해 더 읽어 보세요.*](http://git-scm.com/docs/git-commit) 958 | [*Git `rebase` 커맨드에 대해 더 읽어 보세요.*](http://git-scm.com/docs/git-rebase) 959 | 960 | ### Web Server for Browsing Local Repositories 961 | 962 | Git `instaweb` 커맨드을 사용하면, 즉석에서 `gitweb` 안에서 작업중인 저장소를 둘러 볼 963 | 수 있습니다. 이 커맨드는 `gitweb`과 로컬 저장소를 브라우징 하기 위한 웹 서버를 설정하는 스크립트입니다. 964 | 965 | ```bash 966 | $ git instaweb 967 | ``` 968 | 969 | Opens: 970 | 971 | ![Git instaweb](http://i.imgur.com/Dxekmqc.png) 972 | 973 | [*Git `instaweb` 커맨드에 대해 더 읽어 보세요.*](http://git-scm.com/docs/git-instaweb) 974 | 975 | ### Git Configurations 976 | 977 | `.gitconfig`는 모든 설정이 들어있는 파일입니다. 978 | 979 | #### Aliases 980 | 981 | 알리아스는 커스텀 Git 명령어를 등록할 수 있는 헬퍼입니다. 예를 들어 `git a`로 `git add --all`를 실행하게 할 수 있습니다. 982 | 983 | 알리아스를 추가하려면 `~/.gitconfig`를 찾아 다음 포맷으로 입력하거나 984 | 985 | ``` 986 | [alias] 987 | co = checkout 988 | cm = commit 989 | p = push 990 | # Show verbose output about tags, branches or remotes 991 | tags = tag -l 992 | branches = branch -a 993 | remotes = remote -v 994 | ``` 995 | 996 | 커맨드 라인에서 다음 명령을 입력합니다. 997 | 998 | ```bash 999 | $ git config --global alias.new_alias git_function 1000 | ``` 1001 | 1002 | 예를 들면 1003 | 1004 | ```bash 1005 | $ git config --global alias.cm commit 1006 | ``` 1007 | 1008 | 여러 함수를 알리아스하려면 따옴표를 이용하세요. 1009 | 1010 | ```bash 1011 | $ git config --global alias.ac 'add -A . && commit' 1012 | ``` 1013 | 1014 | 여기 몇 가지 유용한 알리아스가 있습니다. 1015 | 1016 | | Alias | Current Command | What to Type | 1017 | | --- | --- | --- | 1018 | | `git cm` | `git commit` | `git config --global alias.cm commit` | 1019 | | `git co` | `git checkout` | `git config --global alias.co checkout` | 1020 | | `git ac` | `git add . -A` `git commit` | `git config --global alias.ac '!git add -A && git commit'` | 1021 | | `git st` | `git status -sb` | `git config --global alias.st 'status -sb'` | 1022 | | `git tags` | `git tag -l` | `git config --global alias.tags 'tag -l'` | 1023 | | `git branches` | `git branch -a` | `git config --global alias.branches 'branch -a'` | 1024 | | `git cleanup` | `git branch --merged \| grep -v '*' \| xargs git branch -d` | `git config --global alias.cleanup "!git branch --merged \| grep -v '*' \| xargs git branch -d"` | 1025 | | `git remotes` | `git remote -v` | `git config --global alias.remotes 'remote -v'` | 1026 | | `git lg` | `git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --` | `git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"` | 1027 | 1028 | *일부 알리아스는 [@mathiasbynens](https://github.com/mathiasbynens) 님의 dotfiles에서 가져왔습니다.(https://github.com/mathiasbynens/dotfiles/blob/master/.gitconfig)* 1029 | 1030 | #### Auto-correct 1031 | 1032 | 현재 `git comit`를 치면 이런 결과를 보실 수 있습니다. 1033 | 1034 | ```bash 1035 | $ git comit -m "Message" 1036 | # git: 'comit' is not a git command. See 'git --help'. 1037 | 1038 | # Did you mean this? 1039 | # commit 1040 | ``` 1041 | 1042 | `comit`을 쳤을 때 `commit`을 부르려면, 자동 교정을 켜두세요. 1043 | 1044 | ```bash 1045 | $ git config --global help.autocorrect 1 1046 | ``` 1047 | 1048 | 이제 이런 결과를 보실 수 있습니다. 1049 | 1050 | ```bash 1051 | $ git comit -m "Message" 1052 | # WARNING: You called a Git command named 'comit', which does not exist. 1053 | # Continuing under the assumption that you meant 'commit' 1054 | # in 0.1 seconds automatically... 1055 | ``` 1056 | 1057 | #### Color 1058 | 1059 | Git 커맨드 라인에 색을 넣으려면 이렇게 하세요. 1060 | 1061 | ```bash 1062 | $ git config --global color.ui 1 1063 | ``` 1064 | 1065 | [*Git `config` 커맨드에 대해 더 읽어 보세요.*](http://git-scm.com/docs/git-config) 1066 | 1067 | ### Git Resources 1068 | 1069 | | Title | Link | 1070 | | ----- | ---- | 1071 | | Official Git Site | http://git-scm.com/ | 1072 | | Official Git Video Tutorials | http://git-scm.com/videos | 1073 | | Code School Try Git | http://try.github.com/ | 1074 | | Introductory Reference & Tutorial for Git | http://gitref.org/ | 1075 | | Official Git Tutorial | http://git-scm.com/docs/gittutorial | 1076 | | Everyday Git | http://git-scm.com/docs/everyday | 1077 | | Git Immersion | http://gitimmersion.com/ | 1078 | | Git for Computer Scientists | http://eagain.net/articles/git-for-computer-scientists/ | 1079 | | Git Magic | http://www-cs-students.stanford.edu/~blynn/gitmagic/ | 1080 | | Git Visualization Playground | http://onlywei.github.io/explain-git-with-d3/#freeplay | 1081 | | Learn Git Branching | http://pcottle.github.io/learnGitBranching/ | 1082 | | A collection of useful .gitignore templates | https://github.com/github/gitignore | 1083 | 1084 | #### Git Books 1085 | 1086 | | Title | Link | 1087 | | ----- | ---- | 1088 | | Pragmatic Version Control Using Git | http://www.pragprog.com/titles/tsgit/pragmatic-version-control-using-git | 1089 | | Pro Git | http://git-scm.com/book | 1090 | | Git Internals PluralSight | https://github.com/pluralsight/git-internals-pdf | 1091 | | Git in the Trenches | http://cbx33.github.com/gitt/ | 1092 | | Version Control with Git | http://www.amazon.com/Version-Control-Git-collaborative-development/dp/1449316387 | 1093 | | Pragmatic Guide to Git | http://www.pragprog.com/titles/pg_git/pragmatic-guide-to-git | 1094 | | Git: Version Control for Everyone | http://www.packtpub.com/git-version-control-for-everyone/book | 1095 | 1096 | #### Git Videos 1097 | 1098 | | Title | Link | 1099 | | ----- | ---- | 1100 | | Linus Torvalds on Git | https://www.youtube.com/watch?v=4XpnKHJAok8 | 1101 | | Introduction to Git with Scott Chacon | https://www.youtube.com/watch?v=ZDR433b0HJY | 1102 | | Git From the Bits Up | https://www.youtube.com/watch?v=MYP56QJpDr4 | 1103 | | Graphs, Hashes, and Compression, Oh My! | https://www.youtube.com/watch?v=ig5E8CcdM9g | 1104 | | GitHub Training & Guides | https://www.youtube.com/watch?list=PLg7s6cbtAD15G8lNyoaYDuKZSKyJrgwB-&v=FyfwLX4HAxM | 1105 | 1106 | #### Git Articles 1107 | 1108 | | Title | Link | 1109 | | ----- | ---- | 1110 | | GitHub Flow | http://scottchacon.com/2011/08/31/github-flow.html | 1111 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Cheat Sheet [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 2 | A collection of cool hidden and not so hidden features of Git and GitHub. This cheat sheet was inspired by [Zach Holman](https://github.com/holman)'s [Git and GitHub Secrets](http://confreaks.tv/videos/aloharuby2012-git-and-github-secrets) talk at Aloha Ruby Conference 2012 ([slides](https://speakerdeck.com/holman/git-and-github-secrets)) and his [More Git and GitHub Secrets](https://vimeo.com/72955426) talk at WDCNZ 2013 ([slides](https://speakerdeck.com/holman/more-git-and-github-secrets)). 3 | 4 | *Shortlink: [`http://git.io/sheet`](http://git.io/sheet)* 5 | 6 | *Read this in other languages: [English](README.md), [한국어](README.ko.md), [日本語](README.ja.md), [简体中文](README.zh-cn.md), [正體中文](README.zh-tw.md).* 7 | 8 | GitHub Cheat Sheet is sponsored by [Snapshot: create interactive professional-quality product photos using AI](https://www.snapshotapp.io/) 9 | 10 | ## Table of Contents 11 | - [GitHub](#github) 12 | - [Ignore Whitespace](#ignore-whitespace) 13 | - [Adjust Tab Space](#adjust-tab-space) 14 | - [Commit History by Author](#commit-history-by-author) 15 | - [Cloning a Repository](#cloning-a-repository) 16 | - [Branch](#branch) 17 | - [Compare all Branches to Another Branch](#compare-all-branches-to-another-branch) 18 | - [Comparing Branches](#comparing-branches) 19 | - [Compare Branches across Forked Repositories](#compare-branches-across-forked-repositories) 20 | - [Gists](#gists) 21 | - [Git.io](#gitio) 22 | - [Keyboard Shortcuts](#keyboard-shortcuts) 23 | - [Line Highlighting in Repositories](#line-highlighting-in-repositories) 24 | - [Closing Issues via Commit Messages](#closing-issues-via-commit-messages) 25 | - [Cross-Link Issues](#cross-link-issues) 26 | - [Locking Conversations](#locking-conversations) 27 | - [CI Status on Pull Requests](#ci-status-on-pull-requests) 28 | - [Filters](#filters) 29 | - [Syntax Highlighting in Markdown Files](#syntax-highlighting-in-markdown-files) 30 | - [Emojis](#emojis) 31 | - [Images/GIFs](#imagesgifs) 32 | - [Embedding Images in GitHub Wiki](#embedding-images-in-github-wiki) 33 | - [Quick Quoting](#quick-quoting) 34 | - [Pasting Clipboard Image to Comments](#pasting-clipboard-image-to-comments) 35 | - [Quick Licensing](#quick-licensing) 36 | - [Task Lists](#task-lists) 37 | - [Task Lists in Markdown Documents](#task-lists-in-markdown-documents) 38 | - [Relative Links](#relative-links) 39 | - [Metadata and Plugin Support for GitHub Pages](#metadata-and-plugin-support-for-github-pages) 40 | - [Viewing YAML Metadata in your Documents](#viewing-yaml-metadata-in-your-documents) 41 | - [Rendering Tabular Data](#rendering-tabular-data) 42 | - [Rendering PDF](#rendering-pdf) 43 | - [Revert a Pull Request](#revert-a-pull-request) 44 | - [Diffs](#diffs) 45 | - [Rendered Prose Diffs](#rendered-prose-diffs) 46 | - [Diffable Maps](#diffable-maps) 47 | - [Expanding Context in Diffs](#expanding-context-in-diffs) 48 | - [Diff or Patch of Pull Request](#diff-or-patch-of-pull-request) 49 | - [Rendering and diffing images](#rendering-and-diffing-images) 50 | - [Hub](#hub) 51 | - [Contribution Guidelines](#contribution-guidelines) 52 | - [CONTRIBUTING file](#contributing-file) 53 | - [ISSUE_TEMPLATE file](#issue_template-file) 54 | - [PULL_REQUEST_TEMPLATE file](#pull_request_template-file) 55 | - [Octicons](#octicons) 56 | - [GitHub Student Developer Pack](#github-student-developer-pack) 57 | - [GitHub Resources](#github-resources) 58 | - [GitHub Talks](#github-talks) 59 | - [SSH keys](#ssh-keys) 60 | - [Profile Image](#profile-image) 61 | - [Repository Templates](#repository-templates) 62 | - [Git](#git) 63 | - [Remove All Deleted Files from the Working Tree](#remove-all-deleted-files-from-the-working-tree) 64 | - [Previous Branch](#previous-branch) 65 | - [Stripspace](#stripspace) 66 | - [Checking out Pull Requests](#checking-out-pull-requests) 67 | - [Empty Commits](#empty-commits) 68 | - [Styled Git Status](#styled-git-status) 69 | - [Styled Git Log](#styled-git-log) 70 | - [Git Query](#git-query) 71 | - [Git Grep](#git-grep) 72 | - [Merged Branches](#merged-branches) 73 | - [Fixup and Autosquash](#fixup-and-autosquash) 74 | - [Web Server for Browsing Local Repositories](#web-server-for-browsing-local-repositories) 75 | - [Git Configurations](#git-configurations) 76 | - [Aliases](#aliases) 77 | - [Auto-Correct](#auto-correct) 78 | - [Color](#color) 79 | - [Git Resources](#git-resources) 80 | - [Git Books](#git-books) 81 | - [Git Videos](#git-videos) 82 | - [Git Articles](#git-articles) 83 | 84 | 85 | ## GitHub 86 | ### Ignore Whitespace 87 | Adding `?w=1` to any diff URL will remove any changes only in whitespace, enabling you to see only the code that has changed. 88 | 89 | ![Diff without whitespace](https://camo.githubusercontent.com/797184940defadec00393e6559b835358a863eeb/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f776869746573706163652e706e67) 90 | 91 | [*Read more about GitHub secrets.*](https://github.com/blog/967-github-secrets) 92 | 93 | ### Adjust Tab Space 94 | Adding `?ts=4` to a diff or file URL will display tab characters as 4 spaces wide instead of the default 8. The number after `ts` can be adjusted to suit your preference. This does not work on Gists, or raw file views, but a [Chrome extension](https://chrome.google.com/webstore/detail/tab-size-on-github/ofjbgncegkdemndciafljngjbdpfmbkn) can automate this. 95 | 96 | Here is a Go source file before adding `?ts=4`: 97 | 98 | ![Before, tab space example](http://i.imgur.com/GIT1Fr0.png) 99 | 100 | ...and this is after adding `?ts=4`: 101 | 102 | ![After, tab space example](http://i.imgur.com/70FL4H9.png) 103 | 104 | ### Commit History by Author 105 | To view all commits on a repo by author add `?author={user}` to the URL. 106 | 107 | ``` 108 | https://github.com/rails/rails/commits/master?author=dhh 109 | ``` 110 | 111 | ![DHH commit history](http://i.imgur.com/S7AE29b.png) 112 | 113 | [*Read more about the differences between commits views.*](https://help.github.com/articles/differences-between-commit-views/) 114 | 115 | ### Cloning a Repository 116 | When cloning a repository the `.git` can be left off the end. 117 | 118 | ```bash 119 | $ git clone https://github.com/tiimgreen/github-cheat-sheet 120 | ``` 121 | 122 | [*Read more about the Git `clone` command.*](http://git-scm.com/docs/git-clone) 123 | 124 | ### Branch 125 | #### Compare all Branches to Another Branch 126 | 127 | If you go to the repo's [Branches](https://github.com/tiimgreen/github-cheat-sheet/branches) page, next to the Commits button: 128 | 129 | ``` 130 | https://github.com/{user}/{repo}/branches 131 | ``` 132 | 133 | ... you would see a list of all branches which are not merged into the main branch. 134 | 135 | From here you can access the compare page or delete a branch with a click of a button. 136 | 137 | ![Compare branches not merged into master in rails/rails repo - https://github.com/rails/rails/branches](http://i.imgur.com/0FEe30z.png) 138 | 139 | #### Comparing Branches 140 | To use GitHub to compare branches, change the URL to look like this: 141 | 142 | ``` 143 | https://github.com/{user}/{repo}/compare/{range} 144 | ``` 145 | 146 | where `{range} = master...4-1-stable` 147 | 148 | For example: 149 | 150 | ``` 151 | https://github.com/rails/rails/compare/master...4-1-stable 152 | ``` 153 | 154 | ![Rails branch compare example](http://i.imgur.com/tIRCOsK.png) 155 | 156 | `{range}` can be changed to things like: 157 | 158 | ``` 159 | https://github.com/rails/rails/compare/master@{1.day.ago}...master 160 | https://github.com/rails/rails/compare/master@{2014-10-04}...master 161 | ``` 162 | 163 | *Here, dates are in the format `YYYY-MM-DD`* 164 | 165 | ![Another compare example](http://i.imgur.com/5dtzESz.png) 166 | 167 | Branches can also be compared in `diff` and `patch` views: 168 | 169 | ``` 170 | https://github.com/rails/rails/compare/master...4-1-stable.diff 171 | https://github.com/rails/rails/compare/master...4-1-stable.patch 172 | ``` 173 | 174 | [*Read more about comparing commits across time.*](https://help.github.com/articles/comparing-commits-across-time/) 175 | 176 | #### Compare Branches across Forked Repositories 177 | To use GitHub to compare branches across forked repositories, change the URL to look like this: 178 | 179 | ``` 180 | https://github.com/{user}/{repo}/compare/{foreign-user}:{branch}...{own-branch} 181 | ``` 182 | 183 | For example: 184 | 185 | ``` 186 | https://github.com/rails/rails/compare/byroot:master...master 187 | ``` 188 | 189 | ![Forked branch compare](http://i.imgur.com/Q1W6qcB.png) 190 | 191 | ### Gists 192 | [Gists](https://gist.github.com/) are an easy way to work with small bits of code without creating a fully fledged repository. 193 | 194 | ![Gist](http://i.imgur.com/VkKI1LC.png?1) 195 | 196 | Add `.pibb` to the end of any Gist URL ([like this](https://gist.github.com/tiimgreen/10545817.pibb)) in order to get the *HTML-only* version suitable for embedding in any other site. 197 | 198 | Gists can be treated as a repository so they can be cloned like any other: 199 | 200 | ```bash 201 | $ git clone https://gist.github.com/tiimgreen/10545817 202 | ``` 203 | 204 | ![Gists](http://i.imgur.com/BcFzabp.png) 205 | 206 | This means you also can modify and push updates to Gists: 207 | 208 | ```bash 209 | $ git commit 210 | $ git push 211 | Username for 'https://gist.github.com': 212 | Password for 'https://tiimgreen@gist.github.com': 213 | ``` 214 | 215 | However, Gists do not support directories. All files need to be added to the repository root. 216 | [*Read more about creating Gists.*](https://help.github.com/articles/creating-gists/) 217 | 218 | ### Git.io 219 | [Git.io](http://git.io) is a simple URL shortener for GitHub. 220 | 221 | ![Git.io](http://i.imgur.com/6JUfbcG.png?1) 222 | 223 | You can also use it via pure HTTP using Curl: 224 | 225 | ```bash 226 | $ curl -i http://git.io -F "url=https://github.com/..." 227 | HTTP/1.1 201 Created 228 | Location: http://git.io/abc123 229 | 230 | $ curl -i http://git.io/abc123 231 | HTTP/1.1 302 Found 232 | Location: https://github.com/... 233 | ``` 234 | 235 | [*Read more about Git.io.*](https://github.com/blog/985-git-io-github-url-shortener) 236 | 237 | ### Keyboard Shortcuts 238 | When on a repository page, keyboard shortcuts allow you to navigate easily. 239 | 240 | - Pressing `t` will bring up a file explorer. 241 | - Pressing `w` will bring up the branch selector. 242 | - Pressing `s` will focus the search field for the current repository. Pressing ↓ to select the “All GitHub” option changes the field to search all of GitHub. 243 | - Pressing `l` will edit labels on existing Issues. 244 | - Pressing `y` **when looking at a file** (e.g., `https://github.com/tiimgreen/github-cheat-sheet/blob/master/README.md`) will change your URL to one which, in effect, freezes the page you are looking at. If this code changes, you will still be able to see what you saw at that current time. 245 | 246 | To see all of the shortcuts for the current page press `?`: 247 | 248 | ![Keyboard shortcuts](http://i.imgur.com/y5ZfNEm.png) 249 | 250 | [Read more about search syntax you can use.](https://help.github.com/articles/search-syntax/) 251 | 252 | ### Line Highlighting in Repositories 253 | Either adding, e.g., `#L52` to the end of a code file URL or simply clicking the line number will highlight that line number. 254 | 255 | It also works with ranges, e.g., `#L53-L60`, to select ranges, hold `shift` and click two lines: 256 | 257 | ``` 258 | https://github.com/rails/rails/blob/master/activemodel/lib/active_model.rb#L53-L60 259 | ``` 260 | 261 | ![Line Highlighting](http://i.imgur.com/8AhjrCz.png) 262 | 263 | ### Closing Issues via Commit Messages 264 | If a particular commit fixes an issue, any of the keywords `fix/fixes/fixed`, `close/closes/closed` or `resolve/resolves/resolved`, followed by the issue number, will close the issue once it is committed to the repository's default branch. 265 | 266 | ```bash 267 | $ git commit -m "Fix screwup, fixes #12" 268 | ``` 269 | 270 | This closes the issue and references the closing commit. 271 | 272 | ![Closing Repo](http://i.imgur.com/Uh1gZdx.png) 273 | 274 | [*Read more about closing Issues via commit messages.*](https://help.github.com/articles/closing-issues-via-commit-messages/) 275 | 276 | ### Cross-Link Issues 277 | If you want to link to another issue in the same repository, simply type hash `#` then the issue number, and it will be auto-linked. 278 | 279 | To link to an issue in another repository, `{user}/{repo}#ISSUE_NUMBER`, e.g., `tiimgreen/toc#12`. 280 | 281 | ![Cross-Link Issues](https://camo.githubusercontent.com/447e39ab8d96b553cadc8d31799100190df230a8/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f7265666572656e6365732e706e67) 282 | 283 | ### Locking Conversations 284 | Pull Requests and Issues can now be locked by owners or collaborators of the repo. 285 | 286 | ![Lock conversation](https://cloud.githubusercontent.com/assets/2723/3221693/bf54dd44-f00d-11e3-8eb6-bb51e825bc2c.png) 287 | 288 | This means that users who are not collaborators on the project will no longer be able to comment. 289 | 290 | ![Comments locked](https://cloud.githubusercontent.com/assets/2723/3221775/d6e513b0-f00e-11e3-9721-2131cb37c906.png) 291 | 292 | [*Read more about locking conversations.*](https://github.com/blog/1847-locking-conversations) 293 | 294 | 295 | ### CI Status on Pull Requests 296 | If set up correctly, every time you receive a Pull Request, [Travis CI](https://travis-ci.org/) will build that Pull Request just like it would every time you make a new commit. Read more about how to [get started with Travis CI](http://docs.travis-ci.com/user/getting-started/). 297 | 298 | [![Travis CI status](https://cloud.githubusercontent.com/assets/1687642/2700187/3a88838c-c410-11e3-9a46-e65e2a0458cd.png)](https://github.com/octokit/octokit.rb/pull/452) 299 | 300 | [*Read more about the commit status API.*](https://github.com/blog/1227-commit-status-api) 301 | 302 | ### Filters 303 | 304 | Both issues and pull requests allow filtering in the user interface. 305 | 306 | For the Rails repo: https://github.com/rails/rails/issues, the following filter is built by selecting the label "activerecord": 307 | 308 | `is:issue label:activerecord` 309 | 310 | But, you can also find all issues that are NOT labeled activerecord: 311 | 312 | `is:issue -label:activerecord` 313 | 314 | Additionally, this also works for pull requests: 315 | 316 | `is:pr -label:activerecord` 317 | 318 | Github has tabs for displaying open or closed issues and pull requests but you 319 | can also see merged pull requests. Just put the following in the filter: 320 | 321 | `is:merged` 322 | 323 | [*Read more about searching issues.*](https://help.github.com/articles/searching-issues/) 324 | 325 | Finally, github now allows you to filter by the Status API's status. 326 | 327 | Pull requests with only successful statuses: 328 | 329 | `status:success` 330 | 331 | [*Read more about searching on the Status API.*](https://github.com/blog/2014-filter-pull-requests-by-status) 332 | 333 | ### Syntax Highlighting in Markdown Files 334 | For example, to syntax highlight Ruby code in your Markdown files write: 335 | 336 | ```ruby 337 | require 'tabbit' 338 | table = Tabbit.new('Name', 'Email') 339 | table.add_row('Tim Green', 'tiimgreen@gmail.com') 340 | puts table.to_s 341 | ``` 342 | 343 | This will produce: 344 | 345 | ```ruby 346 | require 'tabbit' 347 | table = Tabbit.new('Name', 'Email') 348 | table.add_row('Tim Green', 'tiimgreen@gmail.com') 349 | puts table.to_s 350 | ``` 351 | 352 | GitHub uses [Linguist](https://github.com/github/linguist) to perform language detection and syntax highlighting. You can find out which keywords are valid by perusing the [languages YAML file](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml). 353 | 354 | [*Read more about GitHub Flavored Markdown.*](https://help.github.com/articles/github-flavored-markdown/) 355 | 356 | ### Emojis 357 | Emojis can be added to Pull Requests, Issues, commit messages, repository descriptions, etc. using `:name_of_emoji:`. 358 | 359 | The full list of supported Emojis on GitHub can be found at [emoji-cheat-sheet.com](http://www.emoji-cheat-sheet.com/) or [scotch-io/All-Github-Emoji-Icons](https://github.com/scotch-io/All-Github-Emoji-Icons). 360 | A handy emoji search engine can be found at [emoji.muan.co](http://emoji.muan.co/). 361 | 362 | The top 5 used Emojis on GitHub are: 363 | 364 | 1. `:shipit:` 365 | 2. `:sparkles:` 366 | 3. `:-1:` 367 | 4. `:+1:` 368 | 5. `:clap:` 369 | 370 | ### Images/GIFs 371 | Images and GIFs can be added to comments, READMEs etc.: 372 | 373 | ``` 374 | ![Alt Text](http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif) 375 | ``` 376 | 377 | Raw images from the repo can be used by calling them directly.: 378 | 379 | ``` 380 | ![Alt Text](https://github.com/{user}/{repo}/raw/master/path/to/image.gif) 381 | ``` 382 | 383 | ![Peter don't care](http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif) 384 | 385 | All images are cached on GitHub, so if your host goes down, the image will remain available. 386 | 387 | #### Embedding Images in GitHub Wiki 388 | There are multiple ways of embedding images in Wiki pages. There's the standard Markdown syntax (shown above). But there's also a syntax that allows things like specifying the height or width of the image: 389 | 390 | ```markdown 391 | [[ http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif | height = 100px ]] 392 | ``` 393 | 394 | Which produces: 395 | 396 | ![Just a screenshot](http://i.imgur.com/J5bMf7S.png) 397 | 398 | ### Quick Quoting 399 | When on a comment thread and you want to quote something someone previously said, highlight the text and press `r`, this will copy it into your text box in the block-quote format. 400 | 401 | ![Quick Quote](https://f.cloud.github.com/assets/296432/124483/b0fa6204-6ef0-11e2-83c3-256c37fa7abc.gif) 402 | 403 | [*Read more about quick quoting.*](https://github.com/blog/1399-quick-quotes) 404 | 405 | ### Pasting Clipboard Image to Comments 406 | 407 | _(Works on Chrome browsers only)_ 408 | 409 | After taking a screenshot and adding it to the clipboard (mac: `cmd-ctrl-shift-4`), you can simply paste (`cmd-v / ctrl-v`) the image into the comment section and it will be auto-uploaded to github. 410 | 411 | ![Pasting Clipboard Image to Comments](https://cloud.githubusercontent.com/assets/39191/5794265/39c9b65a-9f1b-11e4-9bc7-04e41f59ea5f.png) 412 | 413 | [*Read more about issue attachments.*](https://help.github.com/articles/issue-attachments/) 414 | 415 | ### Quick Licensing 416 | When creating a repository, GitHub gives you the option of adding in a pre-made license: 417 | 418 | ![License](http://i.imgur.com/Chqj4Fg.png) 419 | 420 | You can also add them to existing repositories by creating a new file through the web interface. When the name `LICENSE` is typed in you will get an option to use a template: 421 | 422 | ![License](http://i.imgur.com/fTjQict.png) 423 | 424 | Also works for `.gitignore`. 425 | 426 | [*Read more about open source licensing.*](https://help.github.com/articles/open-source-licensing/) 427 | 428 | ### Task Lists 429 | In Issues and Pull requests check boxes can be added with the following syntax (notice the space): 430 | 431 | ``` 432 | - [ ] Be awesome 433 | - [ ] Prepare dinner 434 | - [ ] Research recipe 435 | - [ ] Buy ingredients 436 | - [ ] Cook recipe 437 | - [ ] Sleep 438 | ``` 439 | 440 | ![Task List](http://i.imgur.com/jJBXhsY.png) 441 | 442 | When they are clicked, they will be updated in the pure Markdown: 443 | 444 | ``` 445 | - [x] Be awesome 446 | - [ ] Prepare dinner 447 | - [x] Research recipe 448 | - [x] Buy ingredients 449 | - [ ] Cook recipe 450 | - [ ] Sleep 451 | ``` 452 | 453 | [*Read more about task lists.*](https://help.github.com/articles/writing-on-github/#task-lists) 454 | 455 | #### Task Lists in Markdown Documents 456 | In full Markdown documents **read-only** checklists can now be added using the following syntax: 457 | 458 | ``` 459 | - [ ] Mercury 460 | - [x] Venus 461 | - [x] Earth 462 | - [x] Moon 463 | - [x] Mars 464 | - [ ] Deimos 465 | - [ ] Phobos 466 | ``` 467 | 468 | - [ ] Mercury 469 | - [x] Venus 470 | - [x] Earth 471 | - [x] Moon 472 | - [x] Mars 473 | - [ ] Deimos 474 | - [ ] Phobos 475 | 476 | [*Read more about task lists in markdown documents.*](https://github.com/blog/1825-task-lists-in-all-markdown-documents) 477 | 478 | ### Relative Links 479 | Relative links are recommended in your Markdown files when linking to internal content. 480 | 481 | ```markdown 482 | [Link to a header](#awesome-section) 483 | [Link to a file](docs/readme) 484 | ``` 485 | 486 | Absolute links have to be updated whenever the URL changes (e.g., repository renamed, username changed, project forked). Using relative links makes your documentation easily stand on its own. 487 | 488 | [*Read more about relative links.*](https://help.github.com/articles/relative-links-in-readmes/) 489 | 490 | ### Metadata and Plugin Support for GitHub Pages 491 | Within Jekyll pages and posts, repository information is available within the `site.github` namespace, and can be displayed, for example, using `{{ site.github.project_title }}`. 492 | 493 | The Jemoji and jekyll-mentions plugins enable [emoji](#emojis) and [@mentions](https://github.com/blog/821) in your Jekyll posts and pages to work just like you'd expect when interacting with a repository on GitHub.com. 494 | 495 | [*Read more about repository metadata and plugin support for GitHub Pages.*](https://github.com/blog/1797-repository-metadata-and-plugin-support-for-github-pages) 496 | 497 | ### Viewing YAML Metadata in your Documents 498 | Many blogging websites, like [Jekyll](http://jekyllrb.com/) with [GitHub Pages](https://pages.github.com), depend on some YAML-formatted metadata at the beginning of your post. GitHub will render this metadata as a horizontal table, for easier reading 499 | 500 | ![YAML metadata](https://camo.githubusercontent.com/47245aa16728e242f74a9a324ce0d24c0b916075/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f36343035302f313232383236372f65303439643063362d323761302d313165332d396464382d6131636432323539393334342e706e67) 501 | 502 | [*Read more about viewing YAML metadata in your documents.*](https://github.com/blog/1647-viewing-yaml-metadata-in-your-documents) 503 | 504 | ### Rendering Tabular Data 505 | GitHub supports rendering tabular data in the form of `.csv` (comma-separated) and `.tsv` (tab-separated) files. 506 | 507 | ![Tabular data](https://camo.githubusercontent.com/1b6dd0157ffb45d9939abf14233a0cb13b3b4dfe/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3238323735392f3937363436322f33323038336463652d303638642d313165332d393262322d3566323863313061353035392e706e67) 508 | 509 | [*Read more about rendering tabular data.*](https://github.com/blog/1601-see-your-csvs) 510 | 511 | ### Rendering PDF 512 | 513 | GitHub supports rendering PDF: 514 | 515 | ![PDF](https://cloud.githubusercontent.com/assets/1000669/7492902/f8493160-f42e-11e4-8cea-1cb4f02757e7.png) 516 | 517 | [*Read more about rendering PDF.*](https://github.com/blog/1974-pdf-viewing) 518 | 519 | ### Revert a Pull Request 520 | After a pull request is merged, you may find it does not help anything or it was a bad decision to merge the pull request. 521 | 522 | You can revert it by clicking the **Revert** button on the right side of a commit in the pull request page to create a pull request with reverted changes to this specific pull request. 523 | 524 | ![Revert button](https://camo.githubusercontent.com/0d3350caf2bb1cba53123ffeafc00ca702b1b164/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f68656c702f70756c6c5f72657175657374732f7265766572742d70756c6c2d726571756573742d6c696e6b2e706e67) 525 | 526 | [*Read more about reverting pull requests*](https://github.com/blog/1857-introducing-the-revert-button) 527 | 528 | ### Diffs 529 | #### Rendered Prose Diffs 530 | Commits and pull requests, including rendered documents supported by GitHub (e.g., Markdown), feature *source* and *rendered* views. 531 | 532 | ![Source / Rendered view](https://github-images.s3.amazonaws.com/help/repository/rendered_prose_diff.png) 533 | 534 | Click the "rendered" button to see the changes as they'll appear in the rendered document. Rendered prose view is handy when you're adding, removing, and editing text: 535 | 536 | ![Rendered Prose Diffs](https://f.cloud.github.com/assets/17715/2003056/3997edb4-862b-11e3-90be-5e9586edecd7.png) 537 | 538 | [*Read more about rendered prose diffs.*](https://github.com/blog/1784-rendered-prose-diffs) 539 | 540 | #### Diffable Maps 541 | Any time you view a commit or pull request on GitHub that includes geodata, GitHub will render a visual representation of what was changed. 542 | 543 | [![Diffable Maps](https://f.cloud.github.com/assets/282759/2090660/63f2e45a-8e97-11e3-9d8b-d4c8078b004e.gif)](https://github.com/benbalter/congressional-districts/commit/2233c76ca5bb059582d796f053775d8859198ec5) 544 | 545 | [*Read more about diffable maps.*](https://github.com/blog/1772-diffable-more-customizable-maps) 546 | 547 | #### Expanding Context in Diffs 548 | Using the *unfold* button in the gutter of a diff, you can reveal additional lines of context with a click. You can keep clicking *unfold* until you've revealed the whole file, and the feature is available anywhere GitHub renders diffs. 549 | 550 | ![Expanding Context in Diffs](https://f.cloud.github.com/assets/22635/1610539/863c1f64-5584-11e3-82bf-151b406a272f.gif) 551 | 552 | [*Read more about expanding context in diffs.*](https://github.com/blog/1705-expanding-context-in-diffs) 553 | 554 | #### Diff or Patch of Pull Request 555 | You can get the diff of a Pull Request by adding a `.diff` or `.patch` 556 | extension to the end of the URL. For example: 557 | 558 | ``` 559 | https://github.com/tiimgreen/github-cheat-sheet/pull/15 560 | https://github.com/tiimgreen/github-cheat-sheet/pull/15.diff 561 | https://github.com/tiimgreen/github-cheat-sheet/pull/15.patch 562 | ``` 563 | 564 | The `.diff` extension would give you this in plain text: 565 | 566 | ``` 567 | diff --git a/README.md b/README.md 568 | index 88fcf69..8614873 100644 569 | --- a/README.md 570 | +++ b/README.md 571 | @@ -28,6 +28,7 @@ All the hidden and not hidden features of Git and GitHub. This cheat sheet was i 572 | - [Merged Branches](#merged-branches) 573 | - [Quick Licensing](#quick-licensing) 574 | - [TODO Lists](#todo-lists) 575 | +- [Relative Links](#relative-links) 576 | - [.gitconfig Recommendations](#gitconfig-recommendations) 577 | - [Aliases](#aliases) 578 | - [Auto-correct](#auto-correct) 579 | @@ -381,6 +382,19 @@ When they are clicked, they will be updated in the pure Markdown: 580 | - [ ] Sleep 581 | 582 | (...) 583 | ``` 584 | 585 | #### Rendering and diffing images 586 | GitHub can display several common image formats, including PNG, JPG, GIF, and PSD. In addition, there are several ways to compare differences between versions of those image formats. 587 | 588 | [![Diffable PSD](https://cloud.githubusercontent.com/assets/2546/3165594/55f2798a-eb56-11e3-92e7-b79ad791a697.gif)](https://github.com/blog/1845-psd-viewing-diffing) 589 | 590 | [*Read more about rendering and diffing images.*](https://help.github.com/articles/rendering-and-diffing-images/) 591 | 592 | ### Hub 593 | [Hub](https://github.com/github/hub) is a command line Git wrapper that gives you extra features and commands that make working with GitHub easier. 594 | 595 | This allows you to do things like: 596 | 597 | ```bash 598 | $ hub clone tiimgreen/toc 599 | ``` 600 | 601 | [*Check out some more cool commands Hub has to offer.*](https://github.com/github/hub#commands) 602 | 603 | ### Contribution Guidelines 604 | GitHub supports adding 3 different files which help users contribute to your project. 605 | These files can either be placed in the root of your repository or a `.github` directory under the root. 606 | 607 | #### CONTRIBUTING File 608 | Adding a `CONTRIBUTING` or `CONTRIBUTING.md` file to either the root of your repository or a `.github` directory will add a link to your file when a contributor creates an Issue or opens a Pull Request. 609 | 610 | ![Contributing Guidelines](https://camo.githubusercontent.com/71995d6b0e620a9ef1ded00a04498241c69dd1bf/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f736b697463682f6973737565732d32303132303931332d3136323533392e6a7067) 611 | 612 | [*Read more about contributing guidelines.*](https://github.com/blog/1184-contributing-guidelines) 613 | 614 | #### ISSUE_TEMPLATE file 615 | You can define a template for all new issues opened in your project. The content of this file will pre-populate the new issue box when users create new issues. Add an `ISSUE_TEMPLATE` or `ISSUE_TEMPLATE.md` file to either the root of your repository or a `.github` directory. 616 | 617 | [*Read more about issue templates.*](https://github.com/blog/2111-issue-and-pull-request-templates) 618 | 619 | [Issue template file generator](https://www.talater.com/open-source-templates/) 620 | 621 | ![GitHub Issue template](https://cloud.githubusercontent.com/assets/25792/13120859/733479fe-d564-11e5-8a1f-a03f95072f7a.png) 622 | 623 | #### PULL_REQUEST_TEMPLATE file 624 | You can define a template for all new pull requests opened in your project. The content of this file will pre-populate the text area when users create pull requests. Add a `PULL_REQUEST_TEMPLATE` or `PULL_REQUEST_TEMPLATE.md` file to either the root of your repository or a `.github` directory. 625 | 626 | [*Read more about pull request templates.*](https://github.com/blog/2111-issue-and-pull-request-templates) 627 | 628 | [Pull request template file generator](https://www.talater.com/open-source-templates/) 629 | 630 | ### Octicons 631 | GitHubs icons (Octicons) have now been open sourced. 632 | 633 | ![Octicons](https://og.github.com/octicons/octicons@1200x630.png) 634 | 635 | [*Read more about GitHub's Octicons*](https://octicons.github.com) 636 | 637 | ### GitHub Student Developer Pack 638 | 639 | If you are a student you will be eligible for the GitHub Student Developer Pack. This gives you free credit, free trials and early access to software that will help you when developing. 640 | 641 | ![GitHub Student Developer Pack](http://i.imgur.com/9ru3K43.png) 642 | 643 | [*Read more about GitHub's Student Developer Pack*](https://education.github.com/pack) 644 | 645 | ### GitHub Resources 646 | | Title | Link | 647 | | ----- | ---- | 648 | | GitHub Explore | https://github.com/explore | 649 | | GitHub Blog | https://github.com/blog | 650 | | GitHub Help | https://help.github.com/ | 651 | | GitHub Training | https://training.github.com/ | 652 | | GitHub Developer | https://developer.github.com/ | 653 | | Github Education (Free Micro Account and other stuff for students) | https://education.github.com/ | 654 | | GitHub Best Practices | [Best Practices List](https://www.datree.io/resources/github-best-practices) | 655 | 656 | #### GitHub Talks 657 | | Title | Link | 658 | | ----- | ---- | 659 | | How GitHub Uses GitHub to Build GitHub | https://www.youtube.com/watch?v=qyz3jkOBbQY | 660 | | Introduction to Git with Scott Chacon of GitHub | https://www.youtube.com/watch?v=ZDR433b0HJY | 661 | | How GitHub No Longer Works | https://www.youtube.com/watch?v=gXD1ITW7iZI | 662 | | Git and GitHub Secrets | https://www.youtube.com/watch?v=Foz9yvMkvlA | 663 | | More Git and GitHub Secrets | https://www.youtube.com/watch?v=p50xsL-iVgU | 664 | 665 | ### SSH keys 666 | 667 | You can get a list of public ssh keys in plain text format by visiting: 668 | 669 | ``` 670 | https://github.com/{user}.keys 671 | ``` 672 | 673 | e.g. [https://github.com/tiimgreen.keys](https://github.com/tiimgreen.keys) 674 | 675 | [*Read more about accessing public ssh keys.*](https://changelog.com/github-exposes-public-ssh-keys-for-its-users/) 676 | 677 | ### Profile Image 678 | 679 | You can get a user's profile image by visiting: 680 | 681 | ``` 682 | https://github.com/{user}.png 683 | ``` 684 | 685 | e.g. [https://github.com/tiimgreen.png](https://github.com/tiimgreen.png) 686 | 687 | ### Repository Templates 688 | 689 | You can enable templating on your repository which allows anyone to copy the directory structure and files, allowing them to instantly use the files (e.g. for a tutorial or if writing boilerplate code). This can be enabled in the settings of your repository. 690 | 691 | ![Convert](https://i.postimg.cc/hGCrVm9F/Template.gif) 692 | 693 | Changing to a template repository will give a new URL endpoint which can be shared and instantly allows users to use your repository as a template. Alternatively, they can go to your repository and click the 'Use as template' button. 694 | 695 | ![Template](https://i.postimg.cc/L8PKCHx0/New-Template.gif) 696 | 697 | [*Read more about using repositories as templates*](https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/) 698 | 699 | ## Git 700 | ### Remove All Deleted Files from the Working Tree 701 | When you delete a lot of files using `/bin/rm` you can use the following command to remove them from the working tree and from the index, eliminating the need to remove each one individually: 702 | 703 | ```bash 704 | $ git rm $(git ls-files -d) 705 | ``` 706 | 707 | For example: 708 | 709 | ```bash 710 | $ git status 711 | On branch master 712 | Changes not staged for commit: 713 | deleted: a 714 | deleted: c 715 | 716 | $ git rm $(git ls-files -d) 717 | rm 'a' 718 | rm 'c' 719 | 720 | $ git status 721 | On branch master 722 | Changes to be committed: 723 | deleted: a 724 | deleted: c 725 | ``` 726 | 727 | ### Previous Branch 728 | To move to the previous branch in Git: 729 | 730 | ```bash 731 | $ git checkout - 732 | # Switched to branch 'master' 733 | 734 | $ git checkout - 735 | # Switched to branch 'next' 736 | 737 | $ git checkout - 738 | # Switched to branch 'master' 739 | ``` 740 | 741 | [*Read more about Git branching.*](http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging) 742 | 743 | ### Stripspace 744 | 745 | Git Stripspace: 746 | 747 | - Strips trailing whitespace 748 | - Collapses newlines 749 | - Adds newline to end of file 750 | 751 | A file must be passed when calling the command, e.g.: 752 | ```bash 753 | $ git stripspace < README.md 754 | ``` 755 | 756 | [*Read more about the Git `stripspace` command.*](http://git-scm.com/docs/git-stripspace) 757 | 758 | ### Checking out Pull Requests 759 | 760 | Pull Requests are special branches on the GitHub repository which can be retrieved locally in several ways: 761 | 762 | Retrieve a specific Pull Request and store it temporarily in `FETCH_HEAD` for quickly `diff`-ing or `merge`-ing: 763 | 764 | ```bash 765 | $ git fetch origin refs/pull/[PR-Number]/head 766 | ``` 767 | 768 | Acquire all Pull Request branches as local remote branches by refspec: 769 | 770 | ```bash 771 | $ git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*' 772 | ``` 773 | 774 | Or setup the remote to fetch Pull Requests automatically by adding these corresponding lines in your repository's `.git/config`: 775 | 776 | ``` 777 | [remote "origin"] 778 | fetch = +refs/heads/*:refs/remotes/origin/* 779 | url = git@github.com:tiimgreen/github-cheat-sheet.git 780 | ``` 781 | 782 | ``` 783 | [remote "origin"] 784 | fetch = +refs/heads/*:refs/remotes/origin/* 785 | url = git@github.com:tiimgreen/github-cheat-sheet.git 786 | fetch = +refs/pull/*/head:refs/remotes/origin/pr/* 787 | ``` 788 | 789 | For Fork-based Pull Request contributions, it's useful to `checkout` a remote branch representing the Pull Request and create a local branch from it: 790 | 791 | ```bash 792 | $ git checkout pr/42 pr-42 793 | ``` 794 | 795 | Or should you work on more repositories, you can globally configure fetching pull requests in the global git config instead. 796 | 797 | ```bash 798 | git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*" 799 | ``` 800 | 801 | This way, you can use the following short commands in all your repositories: 802 | 803 | ```bash 804 | git fetch origin 805 | ``` 806 | 807 | ```bash 808 | git checkout pr/42 809 | ``` 810 | 811 | [*Read more about checking out pull requests locally.*](https://help.github.com/articles/checking-out-pull-requests-locally/) 812 | 813 | ### Empty Commits 814 | Commits can be pushed with no code changes by adding `--allow-empty`: 815 | 816 | ```bash 817 | $ git commit -m "Big-ass commit" --allow-empty 818 | ``` 819 | 820 | Some use-cases for this (that make sense), include: 821 | 822 | - Annotating the start of a new bulk of work or a new feature. 823 | - Documenting when you make changes to the project that aren't code related. 824 | - Communicating with people using your repository. 825 | - The first commit of a repository: `git commit -m "Initial commit" --allow-empty`. 826 | 827 | ### Styled Git Status 828 | Running: 829 | 830 | ```bash 831 | $ git status 832 | ``` 833 | 834 | produces: 835 | 836 | ![git status](http://i.imgur.com/qjPyvXb.png) 837 | 838 | By adding `-sb`: 839 | 840 | ```bash 841 | $ git status -sb 842 | ``` 843 | 844 | this is produced: 845 | 846 | ![git status -sb](http://i.imgur.com/K0OY3nm.png) 847 | 848 | [*Read more about the Git `status` command.*](http://git-scm.com/docs/git-status) 849 | 850 | ### Styled Git Log 851 | Running: 852 | 853 | ```bash 854 | $ git log --all --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative 855 | ``` 856 | 857 | produces: 858 | 859 | ![git log --all --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative](http://i.imgur.com/58eOtkW.png) 860 | 861 | Credit to [Palesz](http://stackoverflow.com/users/88355/palesz) 862 | 863 | *This can be aliased using the instructions found [here](https://github.com/tiimgreen/github-cheat-sheet#aliases).* 864 | 865 | [*Read more about the Git `log` command.*](http://git-scm.com/docs/git-log) 866 | 867 | ### Git Query 868 | A Git query allows you to search all your previous commit messages and find the most recent one matching the query. 869 | 870 | ```bash 871 | $ git show :/query 872 | ``` 873 | 874 | where `query` (case-sensitive) is the term you want to search, this then finds the last one and gives details on the lines that were changed. 875 | 876 | ```bash 877 | $ git show :/typo 878 | ``` 879 | ![git show :/query](http://i.imgur.com/icaGiNt.png) 880 | 881 | *Press `q` to quit.* 882 | 883 | 884 | ### Git Grep 885 | 886 | Git Grep will return a list of lines matching a pattern. 887 | 888 | Running: 889 | ```bash 890 | $ git grep aliases 891 | ``` 892 | will show all the files containing the string *aliases*. 893 | 894 | ![git grep aliases](http://i.imgur.com/DL2zpQ9.png) 895 | 896 | *Press `q` to quit.* 897 | 898 | You can also use multiple flags for more advanced search. For example: 899 | 900 | * `-e` The next parameter is the pattern (e.g., regex) 901 | * `--and`, `--or` and `--not` Combine multiple patterns. 902 | 903 | Use it like this: 904 | ```bash 905 | $ git grep -e pattern --and -e anotherpattern 906 | ``` 907 | 908 | [*Read more about the Git `grep` command.*](http://git-scm.com/docs/git-grep) 909 | 910 | ### Merged Branches 911 | Running: 912 | 913 | ```bash 914 | $ git branch --merged 915 | ``` 916 | 917 | will give you a list of all branches that have been merged into your current branch. 918 | 919 | Conversely: 920 | 921 | ```bash 922 | $ git branch --no-merged 923 | ``` 924 | 925 | will give you a list of branches that have not been merged into your current branch. 926 | 927 | [*Read more about the Git `branch` command.*](http://git-scm.com/docs/git-branch) 928 | 929 | ### Fixup and Autosquash 930 | If there is something wrong with a previous commit (can be one or more from HEAD), for example `abcde`, run the following command after you've amended the problem: 931 | ```bash 932 | $ git commit --fixup=abcde 933 | $ git rebase abcde^ --autosquash -i 934 | ``` 935 | [*Read more about the Git `commit` command.*](http://git-scm.com/docs/git-commit) 936 | [*Read more about the Git `rebase` command.*](http://git-scm.com/docs/git-rebase) 937 | 938 | ### Web Server for Browsing Local Repositories 939 | Use the Git `instaweb` command to instantly browse your working repository in `gitweb`. This command is a simple script to set up `gitweb` and a web server for browsing the local repository. 940 | 941 | ```bash 942 | $ git instaweb 943 | ``` 944 | 945 | opens: 946 | 947 | ![Git instaweb](http://i.imgur.com/Dxekmqc.png) 948 | 949 | [*Read more about the Git `instaweb` command.*](http://git-scm.com/docs/git-instaweb) 950 | 951 | ### Git Configurations 952 | Your `.gitconfig` file contains all your Git configurations. 953 | 954 | #### Aliases 955 | Aliases are helpers that let you define your own git calls. For example you could set `git a` to run `git add --all`. 956 | 957 | To add an alias, either navigate to `~/.gitconfig` and fill it out in the following format: 958 | 959 | ``` 960 | [alias] 961 | co = checkout 962 | cm = commit 963 | p = push 964 | # Show verbose output about tags, branches or remotes 965 | tags = tag -l 966 | branches = branch -a 967 | remotes = remote -v 968 | ``` 969 | 970 | ...or type in the command-line: 971 | 972 | ```bash 973 | $ git config --global alias.new_alias git_function 974 | ``` 975 | 976 | For example: 977 | 978 | ```bash 979 | $ git config --global alias.cm commit 980 | ``` 981 | 982 | For an alias with multiple functions use quotes: 983 | 984 | ```bash 985 | $ git config --global alias.ac 'add -A . && commit' 986 | ``` 987 | 988 | Some useful aliases include: 989 | 990 | | Alias | Command | What to Type | 991 | | --- | --- | --- | 992 | | `git cm` | `git commit` | `git config --global alias.cm commit` | 993 | | `git co` | `git checkout` | `git config --global alias.co checkout` | 994 | | `git ac` | `git add . -A` `git commit` | `git config --global alias.ac '!git add -A && git commit'` | 995 | | `git st` | `git status -sb` | `git config --global alias.st 'status -sb'` | 996 | | `git tags` | `git tag -l` | `git config --global alias.tags 'tag -l'` | 997 | | `git branches` | `git branch -a` | `git config --global alias.branches 'branch -a'` | 998 | | `git cleanup` | `git branch --merged \| grep -v '*' \| xargs git branch -d` | `git config --global alias.cleanup "!git branch --merged \| grep -v '*' \| xargs git branch -d"` | 999 | | `git remotes` | `git remote -v` | `git config --global alias.remotes 'remote -v'` | 1000 | | `git lg` | `git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --` | `git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"` | 1001 | 1002 | *Some Aliases are taken from [@mathiasbynens](https://github.com/mathiasbynens) dotfiles: https://github.com/mathiasbynens/dotfiles/blob/master/.gitconfig* 1003 | 1004 | #### Auto-Correct 1005 | Git gives suggestions for misspelled commands and if auto-correct is enabled the command can be fixed and executed automatically. Auto-correct is enabled by specifying an integer which is the delay in tenths of a second before git will run the corrected command. Zero is the default value where no correcting will take place, and a negative value will run the corrected command with no delay. 1006 | 1007 | For example, if you type `git comit` you will get this: 1008 | 1009 | ```bash 1010 | $ git comit -m "Message" 1011 | # git: 'comit' is not a git command. See 'git --help'. 1012 | 1013 | # Did you mean this? 1014 | # commit 1015 | ``` 1016 | 1017 | Auto-correct can be enabled like this (with a 1.5 second delay): 1018 | 1019 | ```bash 1020 | $ git config --global help.autocorrect 15 1021 | ``` 1022 | 1023 | So now the command `git comit` will be auto-corrected to `git commit` like this: 1024 | 1025 | ```bash 1026 | $ git comit -m "Message" 1027 | # WARNING: You called a Git command named 'comit', which does not exist. 1028 | # Continuing under the assumption that you meant 'commit' 1029 | # in 1.5 seconds automatically... 1030 | ``` 1031 | 1032 | The delay before git will rerun the command is so the user has time to abort. 1033 | 1034 | #### Color 1035 | To add more color to your Git output: 1036 | 1037 | ```bash 1038 | $ git config --global color.ui 1 1039 | ``` 1040 | 1041 | [*Read more about the Git `config` command.*](http://git-scm.com/docs/git-config) 1042 | 1043 | ### Git Resources 1044 | | Title | Link | 1045 | | ----- | ---- | 1046 | | Official Git Site | http://git-scm.com/ | 1047 | | Official Git Video Tutorials | http://git-scm.com/videos | 1048 | | Code School Try Git | http://try.github.com/ | 1049 | | Introductory Reference & Tutorial for Git | http://gitref.org/ | 1050 | | Official Git Tutorial | http://git-scm.com/docs/gittutorial | 1051 | | Everyday Git | http://git-scm.com/docs/everyday | 1052 | | Git Immersion | http://gitimmersion.com/ | 1053 | | Git God | https://github.com/gorosgobe/git-god | 1054 | | Git for Computer Scientists | http://eagain.net/articles/git-for-computer-scientists/ | 1055 | | Git Magic | http://www-cs-students.stanford.edu/~blynn/gitmagic/ | 1056 | | Git Visualization Playground | http://onlywei.github.io/explain-git-with-d3/#freeplay | 1057 | | Learn Git Branching | http://pcottle.github.io/learnGitBranching/ | 1058 | | A collection of useful .gitignore templates | https://github.com/github/gitignore | 1059 | | Unixorn's git-extra-commands collection of git scripts | https://github.com/unixorn/git-extra-commands | 1060 | 1061 | #### Git Books 1062 | | Title | Link | 1063 | | ----- | ---- | 1064 | | Pragmatic Version Control Using Git | https://pragprog.com/titles/tsgit/pragmatic-version-control-using-git | 1065 | | Pro Git | http://git-scm.com/book | 1066 | | Git Internals PluralSight | https://github.com/pluralsight/git-internals-pdf | 1067 | | Git in the Trenches | http://cbx33.github.io/gitt/ | 1068 | | Version Control with Git | http://www.amazon.com/Version-Control-Git-collaborative-development/dp/1449316387 | 1069 | | Pragmatic Guide to Git | https://pragprog.com/titles/pg_git/pragmatic-guide-to-git | 1070 | | Git: Version Control for Everyone | https://www.packtpub.com/application-development/git-version-control-everyone | 1071 | 1072 | #### Git Videos 1073 | | Title | Link | 1074 | | ----- | ---- | 1075 | | Linus Torvalds on Git | https://www.youtube.com/watch?v=4XpnKHJAok8 | 1076 | | Introduction to Git with Scott Chacon | https://www.youtube.com/watch?v=ZDR433b0HJY | 1077 | | Git From the Bits Up | https://www.youtube.com/watch?v=MYP56QJpDr4 | 1078 | | Graphs, Hashes, and Compression, Oh My! | https://www.youtube.com/watch?v=ig5E8CcdM9g | 1079 | | GitHub Training & Guides | https://www.youtube.com/watch?list=PLg7s6cbtAD15G8lNyoaYDuKZSKyJrgwB-&v=FyfwLX4HAxM | 1080 | 1081 | #### Git Articles 1082 | | Title | Link | 1083 | | ----- | ---- | 1084 | | GitHub Flow | http://scottchacon.com/2011/08/31/github-flow.html | 1085 | | Migrating to Git Large File Storate (Git LFS) | http://vooban.com/en/tips-articles-geek-stuff/migrating-to-git-lfs-for-developing-deep-learning-applications-with-large-files/ | 1086 | -------------------------------------------------------------------------------- /README.zh-cn.md: -------------------------------------------------------------------------------- 1 | # GitHub秘籍 [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 2 | Git 和 Github 秘籍,灵感来自于 [Zach Holman](https://github.com/holman) 在 2012 年 Aloha Ruby Conference 和 2013 年 WDCNZ 上所做的演讲:[Git and GitHub Secrets](http://www.confreaks.com/videos/1229-aloharuby2012-git-and-github-secrets)([slides](https://speakerdeck.com/holman/git-and-github-secrets)) 和 [More Git and GitHub Secrets](https://vimeo.com/72955426)([slides](https://speakerdeck.com/holman/more-git-and-github-secrets))。 3 | 4 | *其他语言版本: [English](README.md), [한국어](README.ko.md), [日本語](README.ja.md), [简体中文](README.zh-cn.md), [正體中文](README.zh-tw.md).* 5 | 6 | # 目录 7 | - [GitHub](#github) 8 | - [不比较空白字符](#不比较空白字符) 9 | - [调整 Tab 字符所代表的空格数](#调整-tab-字符所代表的空格数) 10 | - [查看某个用户的 Commit 历史](#查看某个用户的-commit-历史) 11 | - [仓库克隆](#仓库克隆) 12 | - [分支](#分支) 13 | - [将某个分支与其他所有分支进行对比](#将某个分支与其他所有分支进行对比) 14 | - [比较分支](#比较分支) 15 | - [比较不同派生库的分支](#比较不同派生库的分支) 16 | - [Gists](#gists) 17 | - [Git.io](#gitio) 18 | - [键盘快捷键](#键盘快捷键) 19 | - [整行高亮](#整行高亮) 20 | - [用 Commit 信息关闭 Issue](#用-commit-信息关闭-issue) 21 | - [链接其他仓库的 Issue](#链接其他仓库的-issue) 22 | - [锁定项目对话功能](#锁定项目对话功能) 23 | - [设置 CI 对每条 Pull Request 都进行构建](#设置-ci-对每条-pull-request-都进行构建) 24 | - [Markdown 文件语法高亮](#markdown-文件语法高亮) 25 | - [表情符](#表情符) 26 | - [图片 / GIF 动画](#图片--gif-动画) 27 | - [在 GitHub Wiki 中引用图片](#在-github-wiki-中引用图片) 28 | - [快速引用](#快速引用) 29 | - [粘贴剪贴板中的图片到评论](#粘贴剪贴板中的图片到评论) 30 | - [快速添加许可证文件](#快速添加许可证文件) 31 | - [任务列表](#任务列表) 32 | - [Markdown 文件中的任务列表](#markdown-文件中的任务列表) 33 | - [相对链接](#相对链接) 34 | - [GitHub Pages 的元数据与插件支持](#github-pages-的元数据与插件支持) 35 | - [查看 YAML 格式的元数据](#查看-yaml-格式的元数据) 36 | - [渲染表格数据](#渲染表格数据) 37 | - [撤销 Pull Request](#撤销-pull-request) 38 | - [Diffs](#diffs) 39 | - [可渲染文档的Diffs](#可渲染文档的diffs) 40 | - [可比较的地图数据](#可比较的地图数据) 41 | - [在 Diff 中展开查看更多的上下文](#在-diff-中展开查看更多的上下文) 42 | - [获取 Pull Request 的 diff 或 patch 文件](#获取-pull-request-的-diff-或-patch-文件) 43 | - [显示图片以及比较图片](#显示图片以及比较图片) 44 | - [Hub](#hub) 45 | - [贡献者指南](#贡献者指南) 46 | - [Octicons](#octicons) 47 | - [GitHub 资源](#github-资源) 48 | - [GitHub 相关演讲视频](#github-相关演讲视频) 49 | - [Git](#git) 50 | - [从工作区去除大量已删除文件](#从工作区去除大量已删除文件) 51 | - [上一个分支](#上一个分支) 52 | - [去除空白](#去除空白) 53 | - [检出 Pull Requests](#检出-pull-requests) 54 | - [没有任何改动的提交](#没有任何改动的提交) 55 | - [美化 Git Status](#美化-git-status) 56 | - [美化 Git Log](#美化-git-log) 57 | - [Git 查询](#git-查询) 58 | - [合并分支](#合并分支) 59 | - [修复有问题的提交以及自动合并](#修复有问题的提交以及自动合并) 60 | - [以网站方式查看本地仓库](#以网站方式查看本地仓库) 61 | - [Git 配置](#git-配置) 62 | - [Git 命令自定义别名](#git-命令自定义别名) 63 | - [自动更正](#自动更正) 64 | - [颜色输出](#颜色输出) 65 | - [Git 资源](#git-资源) 66 | - [Git 参考书籍](#git-参考书籍) 67 | 68 | ## GitHub 69 | ### 不比较空白字符 70 | 71 | 在任意 diff 页面的 UR L后加上 `?w=1`,可以去掉那些只是空白字符的改动,使你能更专注于代码改动。 72 | 73 | ![Diff without whitespace](https://camo.githubusercontent.com/797184940defadec00393e6559b835358a863eeb/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f776869746573706163652e706e67) 74 | 75 | [*详见 GitHub secrets.*](https://github.com/blog/967-github-secrets) 76 | 77 | ### 调整 Tab 字符所代表的空格数 78 | 在 diff 或文件的 URL 后面加上 `?ts=4` ,这样当显示 tab 字符的长度时就会是 4 个空格的长度,不再是默认的 8 个空格。 `ts` 后面的数字还可以根据你个人的偏好进行修改。这个技巧不适用于 Gists,或者以 Raw 格式查看文件, 但有浏览器扩展插件可以帮你自动调整: [Chrome 扩展](https://chrome.google.com/webstore/detail/github-tab-size/ofjbgncegkdemndciafljngjbdpfmbkn)。 79 | 80 | 下面以一个 Go 语言源文件为例,看看在 URL 里添加 `?ts=4` 参数的效果。添加前: 81 | 82 | ![Before, tab space example](http://i.imgur.com/GIT1Fr0.png) 83 | 84 | ... 添加后的样子: 85 | 86 | ![After, tab space example](http://i.imgur.com/70FL4H9.png) 87 | 88 | ### 查看用户的全部 Commit 历史 89 | 在 Commits 页面 URL 后加上 `?author={user}` 查看用户全部的提交。 90 | 91 | ``` 92 | https://github.com/rails/rails/commits/master?author=dhh 93 | ``` 94 | 95 | ![DHH commit history](http://i.imgur.com/S7AE29b.png) 96 | 97 | [*深入了解提交视图之间的区别*](https://help.github.com/articles/differences-between-commit-views) 98 | 99 | ### 仓库克隆 100 | 当克隆仓库时可以不要那个`.git`后缀。 101 | 102 | ```bash 103 | $ git clone https://github.com/tiimgreen/github-cheat-sheet 104 | ``` 105 | 106 | [*更多对 Git `clone` 命令的介绍.*](http://git-scm.com/docs/git-clone) 107 | 108 | ### 分支 109 | #### 将某个分支与其他所有分支进行对比 110 | 111 | 当你查看某个仓库的分支(Branches)页面(紧挨着 Commits 链接)时 112 | 113 | ``` 114 | https://github.com/{user}/{repo}/branches 115 | ``` 116 | 你会看到一个包含所有未合并的分支的列表。 117 | 118 | 在这里你可以访问分支比较页面或删除某个分支。 119 | 120 | ![Compare branches not merged into master in rails/rails repo - https://github.com/rails/rails/branches](http://i.imgur.com/0FEe30z.png) 121 | 122 | #### 比较分支 123 | 124 | 如果要在 GitHub 上直接比较两个分支,可以使用如下形式的 URL : 125 | 126 | ``` 127 | https://github.com/{user}/{repo}/compare/{range} 128 | ``` 129 | 130 | 其中 `{range} = master...4-1-stable` 131 | 132 | 例如: 133 | 134 | ``` 135 | https://github.com/rails/rails/compare/master...4-1-stable 136 | ``` 137 | 138 | ![Rails branch compare example](http://i.imgur.com/tIRCOsK.png) 139 | 140 | `{range}` 参数还可以使用下面的形式: 141 | 142 | ``` 143 | https://github.com/rails/rails/compare/master@{1.day.ago}...master 144 | https://github.com/rails/rails/compare/master@{2014-10-04}...master 145 | ``` 146 | 147 | *日期格式 `YYYY-MM-DD`* 148 | 149 | ![Another compare example](http://i.imgur.com/5dtzESz.png) 150 | 151 | 在 `diff` 和 `patch` 页面里也可以比较分支: 152 | 153 | ``` 154 | https://github.com/rails/rails/compare/master...4-1-stable.diff 155 | https://github.com/rails/rails/compare/master...4-1-stable.patch 156 | ``` 157 | 158 | [*了解更多关于基于时间的 Commit 比较.*](https://help.github.com/articles/comparing-commits-across-time) 159 | 160 | #### 比较不同派生库的分支 161 | 162 | 想要对派生仓库(Forked Repository)之间的分支进行比较,可以使用如下的 URL: 163 | 164 | ``` 165 | https://github.com/user/repo/compare/{foreign-user}:{branch}...{own-branch} 166 | ``` 167 | 168 | 例如: 169 | 170 | ``` 171 | https://github.com/rails/rails/compare/byroot:master...master 172 | ``` 173 | 174 | ![Forked branch compare](http://i.imgur.com/Q1W6qcB.png) 175 | 176 | ### Gists 177 | 178 | [Gists](https://gist.github.com/) 方便我们管理代码片段,不必使用功能齐全的仓库。 179 | 180 | ![Gist](http://i.imgur.com/VkKI1LC.png?1) 181 | 182 | Gist 的 URL 后加上 `.pibb`([像这样](https://gist.github.com/tiimgreen/10545817.pibb))可以得到便于嵌入到其他网站 的 HTML 代码。 183 | 184 | Gists 可以像任何标准仓库一样被克隆。 185 | 186 | ```bash 187 | $ git clone https://gist.github.com/tiimgreen/10545817 188 | ``` 189 | 190 | ![Gists](http://i.imgur.com/BcFzabp.png) 191 | 192 | 这意味着你可以像 Github 仓库一样修改和更新 Gists : 193 | 194 | ```bash 195 | $ git commit 196 | $ git push 197 | Username for 'https://gist.github.com': 198 | Password for 'https://tiimgreen@gist.github.com': 199 | ``` 200 | 201 | 但是, Gists 不支持目录。所有文件都必须添加在仓库的根目录下。 202 | [*进一步了解如何创建 Gists.*](https://help.github.com/articles/creating-gists) 203 | 204 | ### Git.io 205 | [Git.io](http://git.io)是 Github 的短网址服务。 206 | 207 | ![Git.io](http://i.imgur.com/6JUfbcG.png?1) 208 | 209 | 你可以通过 Curl 命令以普通 HTTP 协议使用它: 210 | 211 | ```bash 212 | $ curl -i http://git.io -F "url=https://github.com/..." 213 | HTTP/1.1 201 Created 214 | Location: http://git.io/abc123 215 | 216 | $ curl -i http://git.io/abc123 217 | HTTP/1.1 302 Found 218 | Location: https://github.com/... 219 | ``` 220 | 221 | [*进一步了解 Git.io.*](https://github.com/blog/985-git-io-github-url-shortener) 222 | 223 | ### 键盘快捷键 224 | 225 | 在仓库页面上提供了快捷键方便快速导航。 226 | 227 | - 按 `t` 键打开一个文件浏览器。 228 | - 按 `w` 键打开分支选择菜单。 229 | - 按 `s` 键聚焦光标到当前仓库的搜索框。此时按退格键就会从搜索当前仓库切换到搜索整个 Github 网站。 230 | - 按 `l` 键编辑 Issue 列表页的标签。 231 | - **查看文件内容时**(如:`https://github.com/tiimgreen/github-cheat-sheet/blob/master/README.md`),按 `y` 键将会冻结这个页面,这样就算代码被修改了也不会影响你当前看到的。 232 | 233 | 按`?`查看当前页面支持的快捷键列表: 234 | 235 | ![Keyboard shortcuts](http://i.imgur.com/y5ZfNEm.png) 236 | 237 | [*进一步了解可用的搜索语法.*](https://help.github.com/articles/search-syntax/) 238 | 239 | ### 整行高亮 240 | 241 | 在代码文件地址 URL 后加上`#L52`或者单击行号 52 都会将第 52 行代码高亮显示。 242 | 243 | 多行高亮也可以,比如用`#L53-L60`选择范围,或者按住 `shift` 键,然后再点击选择的两行。 244 | 245 | ``` 246 | https://github.com/rails/rails/blob/master/activemodel/lib/active_model.rb#L53-L60 247 | ``` 248 | 249 | ![整行高亮](http://i.imgur.com/8AhjrCz.png) 250 | 251 | ### 用 Commit 信息关闭 Issue 252 | 253 | 如果某个提交修复了一个 Issue,当提交到 master 分支时,提交信息里可以使用 `fix/fixes/fixed`, `close/closes/closed` 或者 `resolve/resolves/resolved` 等关键词,后面再跟上 Issue 号,这样就会关闭这个 Issue 。 254 | 255 | ```bash 256 | $ git commit -m "Fix screwup, fixes #12" 257 | ``` 258 | 259 | 这将会关闭 Issue #12,并且在 Issue 讨论列表里关联引用这次提交。 260 | 261 | ![Closing Repo](http://i.imgur.com/Uh1gZdx.png) 262 | 263 | [*进一步了解通过提交信息关闭 Issue.*](https://help.github.com/articles/closing-issues-via-commit-messages) 264 | 265 | ### 链接其他仓库的 Issue 266 | 如果你想引用到同一个仓库中的一个 Issue,只需使用井号 `#` 加上 Issue 号,这样就会自动创建到此 Issue 的链接。 267 | 268 | 要链接到其他仓库的 Issue ,就使用`{user}/{repo}#ISSUE_NUMBER`的方式,例如`tiimgreen/toc#12`。 269 | 270 | ![Cross-Link Issues](https://camo.githubusercontent.com/447e39ab8d96b553cadc8d31799100190df230a8/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f7265666572656e6365732e706e67) 271 | 272 | ### 锁定项目对话功能 273 | 现在仓库的管理员和合作者可以将 Pull Requests 和 Issue 的评论功能关闭。 274 | 275 | ![Lock conversation](https://cloud.githubusercontent.com/assets/2723/3221693/bf54dd44-f00d-11e3-8eb6-bb51e825bc2c.png) 276 | 277 | 这样,不是项目合作者的用户就不能在这个项目上使用评论功能。 278 | 279 | ![Comments locked](https://cloud.githubusercontent.com/assets/2723/3221775/d6e513b0-f00e-11e3-9721-2131cb37c906.png) 280 | 281 | [*进一步了解对话锁定功能.*](https://github.com/blog/1847-locking-conversations) 282 | 283 | ### 设置 CI 对每条 Pull Request 都进行构建 284 | 如果配置正确,[Travis CI](https://travis-ci.org/) 会为每个你收到的 Pull Request 执行构建,就像每次提交也会触发构建一样。想了解更多关于 Travis CI 的信息,请参考 [Travis CI入门](http://docs.travis-ci.com/user/getting-started/)。 285 | 286 | [![Travis CI status](https://cloud.githubusercontent.com/assets/1687642/2700187/3a88838c-c410-11e3-9a46-e65e2a0458cd.png)](https://github.com/octokit/octokit.rb/pull/452) 287 | 288 | [*进一步了解提交状态 API.*](https://github.com/blog/1227-commit-status-api) 289 | 290 | ### Markdown 文件语法高亮 291 | 例如,可以像下面这样在你的 Markdown 文件里为 Ruby 代码添加语法高亮: 292 | 293 | ```ruby 294 | require 'tabbit' 295 | table = Tabbit.new('Name', 'Email') 296 | table.add_row('Tim Green', 'tiimgreen@gmail.com') 297 | puts table.to_s 298 | ``` 299 | 300 | 效果如下: 301 | 302 | ```ruby 303 | require 'tabbit' 304 | table = Tabbit.new('Name', 'Email') 305 | table.add_row('Tim Green', 'tiimgreen@gmail.com') 306 | puts table.to_s 307 | ``` 308 | 309 | Github使用 [Linguist](https://github.com/github/linguist) 做语言识别和语法高亮。你可以仔细阅读 [languages YAML file](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml),了解有哪些可用的关键字。 310 | 311 | [*进一步了解 GitHub Flavored Markdown.*](https://help.github.com/articles/github-flavored-markdown) 312 | 313 | ### 表情符 314 | 315 | 可以在 Pull Requests, Issues, 提交消息, Markdown 文件里加入表情符。使用方法 `:name_of_emoji:` 316 | 317 | ``` 318 | :smile: 319 | ``` 320 | 将输出一个笑脸: 321 | 322 | :smile: 323 | 324 | Github 支持的完整表情符号列表详见[emoji-cheat-sheet.com](http://www.emoji-cheat-sheet.com/) 或 [scotch-io/All-Github-Emoji-Icons](https://github.com/scotch-io/All-Github-Emoji-Icons)。 325 | 326 | Github 上使用最多的5个表情符号是: 327 | 328 | 1. `:shipit:` 329 | 2. `:sparkles:` 330 | 3. `:-1:` 331 | 4. `:+1:` 332 | 5. `:clap:` 333 | 334 | ### 图片 / GIF 动画 335 | 注释和README等文件里也可以使用图片和 GIF 动画: 336 | 337 | ``` 338 | ![Alt Text](http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif) 339 | ``` 340 | 341 | 仓库中的图片可以被直接引用: 342 | 343 | ``` 344 | ![Alt Text](https://github.com/{user}/{repo}/raw/master/path/to/image.gif) 345 | ``` 346 | 347 | ![Peter don't care](http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif) 348 | 349 | 所有图片都缓存在 Github,不用担心你的站点不能访问时就看不到图片了。 350 | 351 | #### 在 GitHub Wiki 中引用图片 352 | 有多种方法可以在 Wiki 页面里嵌入图片。既可以像上一条里那样使用标准的 Markdown 语法,也可以像下面这样指定图片的高度或宽度: 353 | 354 | ```markdown 355 | [[ http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif | height = 100px ]] 356 | ``` 357 | 结果: 358 | 359 | ![Just a screenshot](http://i.imgur.com/J5bMf7S.png) 360 | 361 | ### 快速引用 362 | 在主题评论中引用之前某个人所说的,只需选中文本,然后按 `r` 键,想要的就会以引用的形式复制到你的输入框里。 363 | 364 | ![Quick Quote](https://f.cloud.github.com/assets/296432/124483/b0fa6204-6ef0-11e2-83c3-256c37fa7abc.gif) 365 | 366 | [*进一步了解快速引用.*](https://github.com/blog/1399-quick-quotes) 367 | 368 | ### 粘贴剪贴板中的图片到评论 369 | 370 | _(仅适用于 Chrome 浏览器)_ 371 | 372 | 当截屏图片复制到剪贴板后(mac 上用 `cmd-ctrl-shift-4`),你可以用(`cmd-v / ctrl-v`)把图片粘贴到评论框里,然后它就会自动上传到 Github。 373 | 374 | ![Pasting Clipboard Image to Comments](https://cloud.githubusercontent.com/assets/39191/5794265/39c9b65a-9f1b-11e4-9bc7-04e41f59ea5f.png) 375 | 376 | [*进一步了解在 issue 中使用附件*](https://help.github.com/articles/issue-attachments) 377 | 378 | 379 | ### 快速添加许可证文件 380 | 创建一个仓库时,Github会为你提供一个预置的软件许可列表: 381 | 382 | ![License](http://i.imgur.com/Chqj4Fg.png) 383 | 384 | 对于已有的仓库,可以通过 web 界面创建文件来添加软件许可。输入`LICENSE`作为文件名后,同样可以从预置的列表中选择一个作为模板。 385 | 386 | ![License](http://i.imgur.com/fTjQict.png) 387 | 388 | 这个技巧也适用于 `.gitignore` 文件。 389 | 390 | [*进一步了解开源许可证*](https://help.github.com/articles/open-source-licensing) 391 | 392 | ### 任务列表 393 | Issues 和 Pull requests 里可以添加复选框,语法如下(注意空白符): 394 | 395 | ``` 396 | - [ ] Be awesome 397 | - [ ] Prepare dinner 398 | - [ ] Research recipe 399 | - [ ] Buy ingredients 400 | - [ ] Cook recipe 401 | - [ ] Sleep 402 | ``` 403 | 404 | ![Task List](http://i.imgur.com/jJBXhsY.png) 405 | 406 | 当项目被选中时,它对应的 Markdown 源码也被更新了: 407 | 408 | ``` 409 | - [x] Be awesome 410 | - [ ] Prepare dinner 411 | - [x] Research recipe 412 | - [x] Buy ingredients 413 | - [ ] Cook recipe 414 | - [ ] Sleep 415 | ``` 416 | 417 | [*进一步了解任务列表.*](https://help.github.com/articles/writing-on-github#task-lists) 418 | 419 | #### Markdown 文件中的任务列表 420 | 421 | 在完全适配Markdown语法的文件中可以使用以下语法加入一个**只读**的任务列表 422 | 423 | 424 | ``` 425 | - [ ] Mercury 426 | - [x] Venus 427 | - [x] Earth 428 | - [x] Moon 429 | - [x] Mars 430 | - [ ] Deimos 431 | - [ ] Phobos 432 | ``` 433 | 434 | - [ ] Mercury 435 | - [x] Venus 436 | - [x] Earth 437 | - [x] Moon 438 | - [x] Mars 439 | - [ ] Deimos 440 | - [ ] Phobos 441 | 442 | [*进一步了解 Markdown 文件中的任务列表*](https://github.com/blog/1825-task-lists-in-all-markdown-documents) 443 | 444 | ### 相对链接 445 | Markdown文件里链接到内部内容时推荐使用相对链接。 446 | 447 | ```markdown 448 | [Link to a header](#awesome-section) 449 | [Link to a file](docs/readme) 450 | ``` 451 | 绝对链接会在 URL 改变时(例如重命名仓库、用户名改变,建立分支项目)被更新。使用相对链接能够保证你的文档不受此影响。 452 | 453 | [*进一步了解相对链接.*](https://help.github.com/articles/relative-links-in-readmes) 454 | 455 | ### GitHub Pages 的元数据与插件支持 456 | 在 Jekyll 页面和文章里,仓库信息可在 `site.github` 命名空间下找到,也可以显示出来,例如,使用 `{{ site.github.project_title }}`显示项目标题。 457 | 458 | Jemoji 和 jekyll-mentions 插件为你的 Jekyll 文章和页面增加了[emoji](#emojis)和[@mentions](https://github.com/blog/821)功能。 459 | 460 | [*了解更多 GitHub Pages 的元数据和插件支持.*](https://github.com/blog/1797-repository-metadata-and-plugin-support-for-github-pages) 461 | 462 | ### 查看 YAML 格式的元数据 463 | 许多博客站点,比如基于 [Jekyll](http://jekyllrb.com/)的[GitHub Pages](http://pages.github.com/) ,都依赖于一些文章头部的 YAML 格式的元数据。 Github 会将其渲染成一个水平表格,方便阅读。 464 | 465 | ![YAML metadata](https://camo.githubusercontent.com/47245aa16728e242f74a9a324ce0d24c0b916075/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f36343035302f313232383236372f65303439643063362d323761302d313165332d396464382d6131636432323539393334342e706e67) 466 | 467 | [*进一步了解 在文档里查看 YAML 元数据.*](https://github.com/blog/1647-viewing-yaml-metadata-in-your-documents) 468 | 469 | ### 渲染表格数据 470 | 471 | GitHub 支持将 `.csv` (逗号分隔)和 `.tsv` (制表符分隔)格式的文件渲染成表格数据。 472 | 473 | ![Tabular data](https://camo.githubusercontent.com/1b6dd0157ffb45d9939abf14233a0cb13b3b4dfe/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3238323735392f3937363436322f33323038336463652d303638642d313165332d393262322d3566323863313061353035392e706e67) 474 | 475 | [*进一步了解渲染表格数据.*](https://github.com/blog/1601-see-your-csvs) 476 | 477 | ### 撤销 Pull Request 478 | 合并一个 Pull Request 之后,你可能会反悔:要么是这次 Pull Request 没什么用处,要么是还不到合并的时候。 479 | 480 | 此时可以通过 Pull Request 中的 Revert 按钮来撤销一个已合并的 Pull Request 中的 commit。按下按钮后将自动生成一个进行逆操作的 Pull Request。 481 | 482 | ![Revert button](https://camo.githubusercontent.com/0d3350caf2bb1cba53123ffeafc00ca702b1b164/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f68656c702f70756c6c5f72657175657374732f7265766572742d70756c6c2d726571756573742d6c696e6b2e706e67) 483 | 484 | [*进一步了解“撤销”按钮](https://github.com/blog/1857-introducing-the-revert-button) 485 | 486 | ### Diffs 487 | #### 可渲染文档的Diffs 488 | 489 | Commit 和 Pull Request 里包含有 Github 支持的可渲染文档(比如 Markdown)会提供*source* 和 *rendered* 两个视图功能。 490 | 491 | ![Source / Rendered view](https://github-images.s3.amazonaws.com/help/repository/rendered_prose_diff.png) 492 | 493 | 点击 "rendered" 按钮,看看改动在渲染后的显示效果。当你添加、删除或修改文本时,渲染纯文本视图非常方便。 494 | 495 | ![Rendered Prose Diffs](https://f.cloud.github.com/assets/17715/2003056/3997edb4-862b-11e3-90be-5e9586edecd7.png) 496 | 497 | [*进一步了解渲染纯文本视图Diffs.*](https://github.com/blog/1784-rendered-prose-diffs) 498 | 499 | #### 可比较的地图数据 500 | 当你在GitHub上查看一个包含地理数据的 commit 或 pull request时,Github 将以可视化的方式对比版本之间的差异。 501 | 502 | [![Diffable Maps](https://f.cloud.github.com/assets/282759/2090660/63f2e45a-8e97-11e3-9d8b-d4c8078b004e.gif)](https://github.com/benbalter/congressional-districts/commit/2233c76ca5bb059582d796f053775d8859198ec5) 503 | 504 | [*进一步了解可比较的地图数据.*](https://github.com/blog/1772-diffable-more-customizable-maps) 505 | 506 | #### 在 Diff 中展开查看更多的上下文 507 | 你可以通过点击 diff 边栏里的 *unfold* 按钮来多显示几行上下文。你可以一直点击 *unfold* 按钮直到显示了文件的全部内容。这个功能在所有 GitHub 的 diff 功能中都可以使用。 508 | 509 | ![Expanding Context in Diffs](https://f.cloud.github.com/assets/22635/1610539/863c1f64-5584-11e3-82bf-151b406a272f.gif) 510 | 511 | [*进一步了解展开 Diff 上下文.*](https://github.com/blog/1705-expanding-context-in-diffs) 512 | 513 | #### 获取 Pull Request 的 diff 或 patch 文件 514 | 在 Pull Request 的 URL 后面加上 `.diff` 或 `.patch` 的扩展名就可以得到它的 diff 或 patch 文件,例如: 515 | 516 | ``` 517 | https://github.com/tiimgreen/github-cheat-sheet/pull/15 518 | https://github.com/tiimgreen/github-cheat-sheet/pull/15.diff 519 | https://github.com/tiimgreen/github-cheat-sheet/pull/15.patch 520 | ``` 521 | `.diff` 扩展会使用普通文本格式显示如下内容: 522 | 523 | ``` 524 | diff --git a/README.md b/README.md 525 | index 88fcf69..8614873 100644 526 | --- a/README.md 527 | +++ b/README.md 528 | @@ -28,6 +28,7 @@ All the hidden and not hidden features of Git and GitHub. This cheat sheet was i 529 | - [Merged Branches](#merged-branches) 530 | - [Quick Licensing](#quick-licensing) 531 | - [TODO Lists](#todo-lists) 532 | +- [Relative Links](#relative-links) 533 | - [.gitconfig Recommendations](#gitconfig-recommendations) 534 | - [Aliases](#aliases) 535 | - [Auto-correct](#auto-correct) 536 | @@ -381,6 +382,19 @@ When they are clicked, they will be updated in the pure Markdown: 537 | - [ ] Sleep 538 | 539 | (...) 540 | ``` 541 | #### 显示图片以及比较图片 542 | GitHub 可以显示包括 PNG、JPG、GIF、PSD 在内的多种图片格式并提供了几种方式来比较这些格式的图片文件版本间的不同。 543 | 544 | [![Diffable PSD](https://cloud.githubusercontent.com/assets/2546/3165594/55f2798a-eb56-11e3-92e7-b79ad791a697.gif)](https://github.com/blog/1845-psd-viewing-diffing) 545 | 546 | [*查看更多关于图片显示和比较*](https://help.github.com/articles/rendering-and-diffing-images) 547 | 548 | ### Hub 549 | [Hub](https://github.com/github/hub) 是一个对 Git 进行了封装的命令行工具,可以帮助你更方便的使用 Github。 550 | 551 | 例如可以像下面这样进行克隆: 552 | 553 | ```bash 554 | $ hub clone tiimgreen/toc 555 | ``` 556 | 557 | [*查看更多 Hub 提供的超酷命令.*](https://github.com/github/hub#commands) 558 | 559 | ### 贡献者指南 560 | 561 | 在仓库的根目录添加一个名为 `CONTRIBUTING` 的文件后,贡献者在新建 Issue 或 Pull Request 时会看到一个指向这个文件的链接。 562 | 563 | ![Contributing Guidelines](https://camo.githubusercontent.com/71995d6b0e620a9ef1ded00a04498241c69dd1bf/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f736b697463682f6973737565732d32303132303931332d3136323533392e6a7067) 564 | 565 | [*进一步了解贡献者指南.*](https://github.com/blog/1184-contributing-guidelines) 566 | 567 | ### Octicons 568 | GitHubs 图标库 (Octicons) 现已开源。 569 | 570 | ![Octicons](https://og.github.com/octicons/octicons@1200x630.png) 571 | 572 | [*进一步了解 GitHub 图标库*](https://octicons.github.com) 573 | 574 | ### GitHub 资源 575 | | 内容 | 链接 | 576 | | ----- | ---- | 577 | | 探索 GitHub | https://github.com/explore | 578 | | GitHub 博客 | https://github.com/blog | 579 | | GitHub 帮助 | https://help.github.com/ | 580 | | GitHub 培训 | http://training.github.com/ | 581 | | GitHub 开发者 | https://developer.github.com/ | 582 | 583 | #### GitHub 相关演讲视频 584 | | 内容 | 链接 | 585 | | ----- | ---- | 586 | | How GitHub Uses GitHub to Build GitHub | https://www.youtube.com/watch?v=qyz3jkOBbQY | 587 | | Introduction to Git with Scott Chacon of GitHub | https://www.youtube.com/watch?v=ZDR433b0HJY | 588 | | How GitHub No Longer Works | https://www.youtube.com/watch?v=gXD1ITW7iZI | 589 | | Git and GitHub Secrets | https://www.youtube.com/watch?v=Foz9yvMkvlA | 590 | | More Git and GitHub Secrets | https://www.youtube.com/watch?v=p50xsL-iVgU | 591 | 592 | ## Git 593 | ### 从工作区去除大量已删除文件 594 | 当用 `/bin/rm` 命令删除了大量文件之后,你可以用下面一条命令从工作区和索引中去除这些文件,以免一个一个的删除: 595 | 596 | ```bash 597 | $ git rm $(git ls-files -d) 598 | ``` 599 | 600 | 例如: 601 | 602 | ```bash 603 | $ git status 604 | On branch master 605 | Changes not staged for commit: 606 | deleted: a 607 | deleted: c 608 | 609 | $ git rm $(git ls-files -d) 610 | rm 'a' 611 | rm 'c' 612 | 613 | $ git status 614 | On branch master 615 | Changes to be committed: 616 | deleted: a 617 | deleted: c 618 | ``` 619 | 620 | ### 上一个分支 621 | 快速检出上一个分支: 622 | 623 | ```bash 624 | $ git checkout - 625 | # Switched to branch 'master' 626 | 627 | $ git checkout - 628 | # Switched to branch 'next' 629 | 630 | $ git checkout - 631 | # Switched to branch 'master' 632 | ``` 633 | 634 | [*进一步了解 Git 分支.*](http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging) 635 | 636 | ### 去除空白 637 | 638 | Git Stripspace 命令可以: 639 | 640 | - 去掉行尾空白符 641 | - 多个空行压缩成一行 642 | - 必要时在文件末尾增加一个空行 643 | 644 | 使用此命令时必须传入一个文件,像这样: 645 | 646 | ```bash 647 | $ git stripspace < README.md 648 | ``` 649 | 650 | [*进一步了解 Git `stripspace` 命令.*](http://git-scm.com/docs/git-stripspace) 651 | 652 | ### 检出 Pull Requests 653 | 对 Github 仓库来说,Pull Request 是种特殊分支, 可以通过以下多种方式取到本地: 654 | 655 | 取出某个特定的 Pull Request 并临时作为本地的 `FETCH_HEAD` 中以便进行快速查看更改( diff )以及合并( merge ): 656 | 657 | ```bash 658 | $ git fetch origin refs/pull/[PR-Number]/head 659 | ``` 660 | 661 | 通过 refspec 获取所有的 Pull Request 为本地分支: 662 | 663 | ```bash 664 | $ git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*' 665 | ``` 666 | 667 | 或在仓库的 `.git/config` 中加入下列设置来自动获取远程仓库中的 Pull Request 668 | ``` 669 | [remote "origin"] 670 | fetch = +refs/heads/*:refs/remotes/origin/* 671 | url = git@github.com:tiimgreen/github-cheat-sheet.git 672 | ``` 673 | 674 | ``` 675 | [remote "origin"] 676 | fetch = +refs/heads/*:refs/remotes/origin/* 677 | url = git@github.com:tiimgreen/github-cheat-sheet.git 678 | fetch = +refs/pull/*/head:refs/remotes/origin/pr/* 679 | ``` 680 | 681 | 对基于派生库的 Pull Request,可以通过先 `checkout` 代表此 Pull Request 的远端分支再由此分支建立一个本地分支: 682 | 683 | ```bash 684 | $ git checkout pr/42 pr-42 685 | ``` 686 | 687 | 操作多个仓库的时候,可以在 Git 中设置获取 Pull Request 的全局选项。 688 | 689 | ```bash 690 | git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*" 691 | ``` 692 | 693 | 此时可以在任意仓库中使用以下命令: 694 | 695 | ```bash 696 | git fetch origin 697 | ``` 698 | 699 | ```bash 700 | git checkout pr/42 701 | ``` 702 | 703 | 704 | [*进一步了解如何本地检出 pull request.*](https://help.github.com/articles/checking-out-pull-requests-locally) 705 | 706 | ### 没有任何改动的提交 707 | 可以使用`--allow-empty`选项强制创建一个没有任何改动的提交: 708 | 709 | ```bash 710 | $ git commit -m "Big-ass commit" --allow-empty 711 | ``` 712 | 713 | 这样做在如下几种情况下是有意义的: 714 | 715 | - 标记新的工作或一个新功能的开始。 716 | - 记录对项目的跟代码无关的改动。 717 | - 跟使用你仓库的其他人交流。 718 | - 作为仓库的第一次提交,因为第一次提交后不能被 rebase: `git commit -m "init repo" --allow-empty`. 719 | 720 | ### 美化 Git Status 721 | 在命令行输入如下命令: 722 | 723 | ```bash 724 | $ git status 725 | ``` 726 | 727 | 可以看到: 728 | 729 | ![git status](http://i.imgur.com/qjPyvXb.png) 730 | 731 | 加上`-sb`选项: 732 | 733 | ```bash 734 | $ git status -sb 735 | ``` 736 | 737 | 这会得到: 738 | 739 | ![git status -sb](http://i.imgur.com/K0OY3nm.png) 740 | 741 | [*进一步了解 Git `status` 命令.*](http://git-scm.com/docs/git-status) 742 | 743 | ### 美化 Git Log 744 | 输入如下命令: 745 | 746 | ```bash 747 | $ git log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative 748 | ``` 749 | 750 | 可以看到: 751 | 752 | ![git log --all --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative](http://i.imgur.com/58eOtkW.png) 753 | 754 | 这要归功于 [Palesz](http://stackoverflow.com/users/88355/palesz) 在 stackoverflow 的回答。 755 | 756 | *这个命令可以被用作别名,详细做法见[这里](#git%E5%91%BD%E4%BB%A4%E8%87%AA%E5%AE%9A%E4%B9%89%E5%88%AB%E5%90%8D)。* 757 | 758 | [*进一步了解 Git `log` 命令.*](http://git-scm.com/docs/git-log) 759 | 760 | ### Git 查询 761 | Git 查询运行你在之前的所有提交信息里进行搜索,找到其中和搜索条件相匹配的最近的一条。 762 | 763 | ```bash 764 | $ git show :/query 765 | ``` 766 | 767 | 这里 `query` (区别大小写)是你想要搜索的词语, 这条命令会找到包含这个词语的最后那个提交并显示变动详情。 768 | 769 | ```bash 770 | $ git show :/typo 771 | ``` 772 | ![git show :/query](http://i.imgur.com/icaGiNt.png) 773 | 774 | * 按 `q` 键退出命令。* 775 | 776 | ### 合并分支 777 | 输入命令: 778 | 779 | ```bash 780 | $ git branch --merged 781 | ``` 782 | 783 | 这会显示所有已经合并到你当前分支的分支列表。 784 | 785 | 相反地: 786 | 787 | ```bash 788 | $ git branch --no-merged 789 | ``` 790 | 791 | 会显示所有还没有合并到你当前分支的分支列表。 792 | 793 | [*进一步了解 Git `branch` 命令.*](http://git-scm.com/docs/git-branch) 794 | 795 | ### 修复有问题的提交以及自动合并 796 | 如果上一个或多个提交包含了错误,可以在你修复问题后使用下列命令处理(假设要修复的提交版本是`abcde`): 797 | ```bash 798 | $ git commit --fixup=abcde 799 | $ git rebase abcde^ --autosquash -i 800 | ``` 801 | [*进一步了解 Git `commit` 命令.*](http://git-scm.com/docs/git-commit) 802 | [*进一步了解 Git `rebase` 命令.*](http://git-scm.com/docs/git-rebase) 803 | 804 | ### 以网站方式查看本地仓库 805 | 使用 Git 的 `instaweb` 可以立即在 `gitweb` 中浏览你的工作仓库。这个命令是个简单的脚本,配置了 `gitweb` 和用来浏览本地仓库的Web服务器。*(译者注:默认需要lighttpd支持)* 806 | 807 | ```bash 808 | $ git instaweb 809 | ``` 810 | 811 | 执行后打开: 812 | 813 | ![Git instaweb](http://i.imgur.com/Dxekmqc.png) 814 | 815 | [*进一步了解 Git `instaweb` 命令.*](http://git-scm.com/docs/git-instaweb) 816 | 817 | ### Git 配置 818 | 所有 Git 配置都保存在你的 `.gitconfig` 文件中。 819 | 820 | #### Git 命令自定义别名 821 | 别名用来帮助你定义自己的 git 命令。比如你可以定义 `git a` 来运行 `git add --all`。 822 | 823 | 要添加一个别名, 一种方法是打开 `~/.gitconfig` 文件并添加如下内容: 824 | 825 | ``` 826 | [alias] 827 | co = checkout 828 | cm = commit 829 | p = push 830 | # Show verbose output about tags, branches or remotes 831 | tags = tag -l 832 | branches = branch -a 833 | remotes = remote -v 834 | ``` 835 | 836 | ...或者在命令行里键入: 837 | 838 | ```bash 839 | $ git config --global alias.new_alias git_function 840 | ``` 841 | 842 | 例如: 843 | 844 | ```bash 845 | $ git config --global alias.cm commit 846 | ``` 847 | 848 | 指向多个命令的别名可以用引号来定义: 849 | 850 | ```bash 851 | $ git config --global alias.ac 'add -A . && commit' 852 | ``` 853 | 854 | 下面列出了一些有用的别名: 855 | 856 | | 别名 Alias | 命令 Command | 如何设置 What to Type | 857 | | --- | --- | --- | 858 | | `git cm` | `git commit` | `git config --global alias.cm commit` | 859 | | `git co` | `git checkout` | `git config --global alias.co checkout` | 860 | | `git ac` | `git add . -A` `git commit` | `git config --global alias.ac '!git add -A && git commit'` | 861 | | `git st` | `git status -sb` | `git config --global alias.st 'status -sb'` | 862 | | `git tags` | `git tag -l` | `git config --global alias.tags 'tag -l'` | 863 | | `git branches` | `git branch -a` | `git config --global alias.branches 'branch -a'` | 864 | | `git cleanup` | `git branch --merged \| grep -v '*' \| xargs git branch -d` | `git config --global alias.cleanup "!git branch --merged \| grep -v '*' \| xargs git branch -d"` | 865 | | `git remotes` | `git remote -v` | `git config --global alias.remotes 'remote -v'` | 866 | | `git lg` | `git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --` | `git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"` | 867 | 868 | #### 自动更正 869 | 如果键入 `git comit` 你会看到如下输出: 870 | 871 | ```bash 872 | $ git comit -m "Message" 873 | # git: 'comit' is not a git command. See 'git --help'. 874 | 875 | # Did you mean this? 876 | # commit 877 | ``` 878 | 879 | 为了在键入 `comit` 调用 `commit`命令,只需启用自动纠错功能: 880 | 881 | ```bash 882 | $ git config --global help.autocorrect 1 883 | ``` 884 | 885 | 现在你就会看到: 886 | 887 | ```bash 888 | $ git comit -m "Message" 889 | # WARNING: You called a Git command named 'comit', which does not exist. 890 | # Continuing under the assumption that you meant 'commit' 891 | # in 0.1 seconds automatically... 892 | ``` 893 | 894 | #### 颜色输出 895 | 要在你的 Git 命令输出里加上颜色的话,可以用如下命令: 896 | 897 | ```bash 898 | $ git config --global color.ui 1 899 | ``` 900 | 901 | [*进一步了解 Git `config` 命令.*](http://git-scm.com/docs/git-config) 902 | 903 | ### Git 资源 904 | | Title | Link | 905 | | ----- | ---- | 906 | | Official Git Site | http://git-scm.com/ | 907 | | Official Git Video Tutorials | http://git-scm.com/videos | 908 | | Code School Try Git | http://try.github.com/ | 909 | | Introductory Reference & Tutorial for Git | http://gitref.org/ | 910 | | Official Git Tutorial | http://git-scm.com/docs/gittutorial | 911 | | Everyday Git | http://git-scm.com/docs/everyday | 912 | | Git Immersion | http://gitimmersion.com/ | 913 | | Git for Computer Scientists | http://eagain.net/articles/git-for-computer-scientists/ | 914 | | Git Magic | http://www-cs-students.stanford.edu/~blynn/gitmagic/ | 915 | | GitHub Training Kit | http://training.github.com/kit | 916 | | Git Visualization Playground | http://onlywei.github.io/explain-git-with-d3/#freeplay | 917 | 918 | #### Git 参考书籍 919 | | Title | Link | 920 | | ----- | ---- | 921 | | Pragmatic Version Control Using Git | http://www.pragprog.com/titles/tsgit/pragmatic-version-control-using-git | 922 | | Pro Git | http://git-scm.com/book | 923 | | Git Internals Pluralsight | https://github.com/pluralsight/git-internals-pdf | 924 | | Git in the Trenches | http://cbx33.github.com/gitt/ | 925 | | Version Control with Git | http://www.amazon.com/Version-Control-Git-collaborative-development/dp/1449316387 | 926 | | Pragmatic Guide to Git | http://www.pragprog.com/titles/pg_git/pragmatic-guide-to-git | 927 | | Git: Version Control for Everyone | http://www.packtpub.com/git-version-control-for-everyone/book | 928 | -------------------------------------------------------------------------------- /README.zh-tw.md: -------------------------------------------------------------------------------- 1 | # GitHub秘笈 [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 2 | Git 和 Github 秘笈,靈感來自於 [Zach Holman](https://github.com/holman) 在 2012 年 Aloha Ruby Conference 和 2013 年 WDCNZ 上所做的演講:[Git and GitHub Secrets](http://www.confreaks.com/videos/1229-aloharuby2012-git-and-github-secrets)([slides](https://speakerdeck.com/holman/git-and-github-secrets)) 和 [More Git and GitHub Secrets](https://vimeo.com/72955426)([slides](https://speakerdeck.com/holman/more-git-and-github-secrets))。 3 | 4 | *其他語言版本: [English](README.md), [한국어](README.ko.md), [日本語](README.ja.md), [簡體中文](README.zh-cn.md), [正體中文](README.zh-tw.md).* 5 | 6 | # 目錄 7 | - [GitHub](#github) 8 | - [不比較空白字串](#不比較空白字串) 9 | - [調整 Tab 字串所代表的空格數](#調整-tab-字串所代表的空格數) 10 | - [查看某個使用者的 Commit 歷史](#查看某個使用者的-commit-歷史) 11 | - [倉庫複製](#倉庫複製) 12 | - [分支](#分支) 13 | - [將某個分支與其他所有分支進行比對](#將某個分支與其他所有分支進行比對) 14 | - [比較分支](#比較分支) 15 | - [比較不同派生庫的分支](#比較不同派生庫的分支) 16 | - [Gists](#gists) 17 | - [Git.io](#gitio) 18 | - [鍵盤快捷鍵](#鍵盤快捷鍵) 19 | - [整行高亮](#整行高亮) 20 | - [用 Commit 訊息關閉 Issue](#用-commit-訊息關閉-issue) 21 | - [連接其他倉庫的 Issue](#連接其他倉庫的-issue) 22 | - [鎖定項目對話功能](#鎖定項目對話功能) 23 | - [設置 CI 對每條 Pull Request 都進行構建](#設置-ci-對每條-pull-request-都進行構建) 24 | - [Markdown 文件語法高亮](#markdown-文件語法高亮) 25 | - [表情符號](#表情符號) 26 | - [圖片 / GIF 動畫](#圖片--gif-動畫) 27 | - [在 GitHub Wiki 中引用圖片](#在-github-wiki-中引用圖片) 28 | - [快速引用](#快速引用) 29 | - [複製貼上剪貼板中的圖片到評論](#複製貼上剪貼板中的圖片到評論) 30 | - [快速添加許可證文件](#快速添加許可證文件) 31 | - [任務列表](#任務列表) 32 | - [Markdown 文件中的任務列表](#markdown-文件中的任務列表) 33 | - [相對連接](#相對連接) 34 | - [GitHub Pages 的中繼資料與插件支持](#github-pages-的中繼資料與插件支持) 35 | - [查看 YAML 格式的中繼資料](#查看-yaml-格式的中繼資料) 36 | - [渲染表格數據](#渲染表格數據) 37 | - [撤銷 Pull Request](#撤銷-pull-request) 38 | - [Diffs](#diffs) 39 | - [可渲染文件的Diffs](#可渲染文件的diffs) 40 | - [可比較的地圖數據](#可比較的地圖數據) 41 | - [在 Diff 中展開查看更多的上下文](#在-diff-中展開查看更多的上下文) 42 | - [獲取 Pull Request 的 diff 或 patch 文件](#獲取-pull-request-的-diff-或-patch-文件) 43 | - [顯示圖片以及比較圖片](#顯示圖片以及比較圖片) 44 | - [Hub](#hub) 45 | - [貢獻者指南](#貢獻者指南) 46 | - [Octicons](#octicons) 47 | - [GitHub 資源](#github-資源) 48 | - [GitHub 相關演講視頻](#github-相關演講視頻) 49 | - [Git](#git) 50 | - [從工作區去除大量已刪除文件](#從工作區去除大量已刪除文件) 51 | - [上一個分支](#上一個分支) 52 | - [去除空白](#去除空白) 53 | - [SSH 金鑰](#ssh-金鑰) 54 | - [檢出 Pull Requests](#檢出-pull-requests) 55 | - [沒有任何改動的提交](#沒有任何改動的提交) 56 | - [美化 Git Status](#美化-git-status) 57 | - [美化 Git Log](#美化-git-log) 58 | - [Git 查詢](#git-查詢) 59 | - [Git Grep](#git-grep) 60 | - [合併分支](#合併分支) 61 | - [修復有問題的提交以及自動合併](#修復有問題的提交以及自動合併) 62 | - [以網站方式查看本地倉庫](#以網站方式查看本地倉庫) 63 | - [Git 設置](#git-設置) 64 | - [Git 命令自定義別名](#git-命令自定義別名) 65 | - [自動更正](#自動更正) 66 | - [顏色輸出](#顏色輸出) 67 | - [Git 資源](#git-資源) 68 | - [Git 參考書籍](#git-參考書籍) 69 | 70 | ## GitHub 71 | ### 不比較空白字串 72 | 73 | 在任意 diff 頁面的 UR L後加上 `?w=1`,可以去掉那些隻是空白字串的改動,使你能更專註於代碼改動。 74 | 75 | ![Diff without whitespace](https://camo.githubusercontent.com/797184940defadec00393e6559b835358a863eeb/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f776869746573706163652e706e67) 76 | 77 | [*詳見 GitHub secrets.*](https://github.com/blog/967-github-secrets) 78 | 79 | ### 調整 Tab 字串所代表的空格數 80 | 在 diff 或文件的 URL 後面加上 `?ts=4` ,這樣當顯示 tab 字串的長度時就會是 4 個空格的長度,不再是默認的 8 個空格。 `ts` 後面的數字還可以根據你個人的偏好進行修改。這個技巧不適用於 Gists,或者以 Raw 格式查看文件, 但有瀏覽器擴展插件可以幫你自動調整: [Chrome 擴展](https://chrome.google.com/webstore/detail/github-tab-size/ofjbgncegkdemndciafljngjbdpfmbkn)。 81 | 82 | 下面以一個 Go 語言原始碼為例,看看在 URL 裡添加 `?ts=4` 參數的效果。添加前: 83 | 84 | ![Before, tab space example](http://i.imgur.com/GIT1Fr0.png) 85 | 86 | ... 添加後的樣子: 87 | 88 | ![After, tab space example](http://i.imgur.com/70FL4H9.png) 89 | 90 | ### 查看使用者的全部 Commit 歷史 91 | 在 Commits 頁面 URL 後加上 `?author={user}` 查看使用者全部的提交。 92 | 93 | ``` 94 | https://github.com/rails/rails/commits/master?author=dhh 95 | ``` 96 | 97 | ![DHH commit history](http://i.imgur.com/S7AE29b.png) 98 | 99 | [*深入了解提交視圖之間的區別*](https://help.github.com/articles/differences-between-commit-views) 100 | 101 | ### 倉庫複製 102 | 當複製倉庫時可以不要那個`.git`後綴。 103 | 104 | ```bash 105 | $ git clone https://github.com/tiimgreen/github-cheat-sheet 106 | ``` 107 | 108 | [*更多對 Git `clone` 命令的介紹.*](http://git-scm.com/docs/git-clone) 109 | 110 | ### 分支 111 | #### 將某個分支與其他所有分支進行比對 112 | 113 | 當你查看某個倉庫的分支(Branches)頁面(緊挨著 Commits 連接)時 114 | 115 | ``` 116 | https://github.com/{user}/{repo}/branches 117 | ``` 118 | 你會看到一個包含所有未合併的分支的列表。 119 | 120 | 在這裡你可以訪問分支比較頁面或刪除某個分支。 121 | 122 | ![Compare branches not merged into master in rails/rails repo - https://github.com/rails/rails/branches](http://i.imgur.com/0FEe30z.png) 123 | 124 | #### 比較分支 125 | 126 | 如果要在 GitHub 上直接比較兩個分支,可以使用如下形式的 URL : 127 | 128 | ``` 129 | https://github.com/{user}/{repo}/compare/{range} 130 | ``` 131 | 132 | 其中 `{range} = master...4-1-stable` 133 | 134 | 例如: 135 | 136 | ``` 137 | https://github.com/rails/rails/compare/master...4-1-stable 138 | ``` 139 | 140 | ![Rails branch compare example](http://i.imgur.com/tIRCOsK.png) 141 | 142 | `{range}` 參數還可以使用下面的形式: 143 | 144 | ``` 145 | https://github.com/rails/rails/compare/master@{1.day.ago}...master 146 | https://github.com/rails/rails/compare/master@{2014-10-04}...master 147 | ``` 148 | 149 | *日期格式 `YYYY-DD-MM`* 150 | 151 | ![Another compare example](http://i.imgur.com/5dtzESz.png) 152 | 153 | 在 `diff` 和 `patch` 頁面裡也可以比較分支: 154 | 155 | ``` 156 | https://github.com/rails/rails/compare/master...4-1-stable.diff 157 | https://github.com/rails/rails/compare/master...4-1-stable.patch 158 | ``` 159 | 160 | [*了解更多關於基於時間的 Commit 比較.*](https://help.github.com/articles/comparing-commits-across-time) 161 | 162 | #### 比較不同派生庫的分支 163 | 164 | 想要對派生倉庫(Forked Repository)之間的分支進行比較,可以使用如下的 URL: 165 | 166 | ``` 167 | https://github.com/user/repo/compare/{foreign-user}:{branch}...{own-branch} 168 | ``` 169 | 170 | 例如: 171 | 172 | ``` 173 | https://github.com/rails/rails/compare/byroot:master...master 174 | ``` 175 | 176 | ![Forked branch compare](http://i.imgur.com/Q1W6qcB.png) 177 | 178 | ### Gists 179 | 180 | [Gists](https://gist.github.com/) 方便我們管理代碼片段,不必使用功能齊全的倉庫。 181 | 182 | ![Gist](http://i.imgur.com/VkKI1LC.png?1) 183 | 184 | Gist 的 URL 後加上 `.pibb`([像這樣](https://gist.github.com/tiimgreen/10545817.pibb))可以得到便於嵌入到其他網站 的 HTML 代碼。 185 | 186 | Gists 可以像任何標準倉庫一樣被複製。 187 | 188 | ```bash 189 | $ git clone https://gist.github.com/tiimgreen/10545817 190 | ``` 191 | 192 | ![Gists](http://i.imgur.com/BcFzabp.png) 193 | 194 | 這意味著你可以像 Github 倉庫一樣修改和更新 Gists : 195 | 196 | ```bash 197 | $ git commit 198 | $ git push 199 | Username for 'https://gist.github.com': 200 | Password for 'https://tiimgreen@gist.github.com': 201 | ``` 202 | 203 | 但是, Gists 不支持目錄。所有文件都必須添加在倉庫的根目錄下。 204 | [*進一步了解如何建立 Gists.*](https://help.github.com/articles/creating-gists) 205 | 206 | ### Git.io 207 | [Git.io](http://git.io)是 Github 的短網址服務。 208 | 209 | ![Git.io](http://i.imgur.com/6JUfbcG.png?1) 210 | 211 | 你可以通過 Curl 命令以普通 HTTP 協議使用它: 212 | 213 | ```bash 214 | $ curl -i http://git.io -F "url=https://github.com/..." 215 | HTTP/1.1 201 Created 216 | Location: http://git.io/abc123 217 | 218 | $ curl -i http://git.io/abc123 219 | HTTP/1.1 302 Found 220 | Location: https://github.com/... 221 | ``` 222 | 223 | [*進一步了解 Git.io.*](https://github.com/blog/985-git-io-github-url-shortener) 224 | 225 | ### 鍵盤快捷鍵 226 | 227 | 在倉庫頁面上提供了快捷鍵方便快速導航。 228 | 229 | - 按 `t` 鍵打開一個文件瀏覽器。 230 | - 按 `w` 鍵打開分支選擇菜單。 231 | - 按 `s` 鍵聚焦游標到當前倉庫的搜索框。此時按刪除鍵就會從搜索當前倉庫切換到搜索整個 Github 網站。 232 | - 按 `l` 鍵編輯 Issue 列表頁的標籤。 233 | - **查看文件內容時**(如:`https://github.com/tiimgreen/github-cheat-sheet/blob/master/README.md`),按 `y` 鍵將會凍結這個頁面,這樣就算代碼被修改了也不會影響你當前看到的。 234 | 235 | 按`?`查看當前頁面支持的快捷鍵列表: 236 | 237 | ![Keyboard shortcuts](http://i.imgur.com/y5ZfNEm.png) 238 | 239 | [*進一步了解可用的搜索語法.*](https://help.github.com/articles/search-syntax/) 240 | 241 | ### 整行高亮 242 | 243 | 在代碼文件地址 URL 後加上`#L52`或者單擊行號 52 都會將第 52 行代碼高亮顯示。 244 | 245 | 多行高亮也可以,比如用`#L53-L60`選擇範圍,或者按住 `shift` 鍵,然後再點擊選擇的兩行。 246 | 247 | ``` 248 | https://github.com/rails/rails/blob/master/activemodel/lib/active_model.rb#L53-L60 249 | ``` 250 | 251 | ![整行高亮](http://i.imgur.com/8AhjrCz.png) 252 | 253 | ### 用 Commit 訊息關閉 Issue 254 | 255 | 如果某個提交修復了一個 Issue,當提交到 master 分支時,提交訊息裡可以使用 `fix/fixes/fixed`, `close/closes/closed` 或者 `resolve/resolves/resolved` 等關鍵詞,後面再跟上 Issue 號,這樣就會關閉這個 Issue 。 256 | 257 | ```bash 258 | $ git commit -m "Fix screwup, fixes #12" 259 | ``` 260 | 261 | 這將會關閉 Issue #12,並且在 Issue 討論列表裡關聯引用這次提交。 262 | 263 | ![Closing Repo](http://i.imgur.com/Uh1gZdx.png) 264 | 265 | [*進一步了解通過提交訊息關閉 Issue.*](https://help.github.com/articles/closing-issues-via-commit-messages) 266 | 267 | ### 連接其他倉庫的 Issue 268 | 如果你想引用到同一個倉庫中的一個 Issue,隻需使用井號 `#` 加上 Issue 號,這樣就會自動建立到此 Issue 的連接。 269 | 270 | 要連接到其他倉庫的 Issue ,就使用`{user}/{repo}#ISSUE_NUMBER`的方式,例如`tiimgreen/toc#12`。 271 | 272 | ![Cross-Link Issues](https://camo.githubusercontent.com/447e39ab8d96b553cadc8d31799100190df230a8/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f7265666572656e6365732e706e67) 273 | 274 | ### 鎖定項目對話功能 275 | 現在倉庫的管理員和合作者可以將 Pull Requests 和 Issue 的評論功能關閉。 276 | 277 | ![Lock conversation](https://cloud.githubusercontent.com/assets/2723/3221693/bf54dd44-f00d-11e3-8eb6-bb51e825bc2c.png) 278 | 279 | 這樣,不是項目合作者的使用者就不能在這個項目上使用評論功能。 280 | 281 | ![Comments locked](https://cloud.githubusercontent.com/assets/2723/3221775/d6e513b0-f00e-11e3-9721-2131cb37c906.png) 282 | 283 | [*進一步了解對話鎖定功能.*](https://github.com/blog/1847-locking-conversations) 284 | 285 | ### 設置 CI 對每條 Pull Request 都進行構建 286 | 如果設置正確,[Travis CI](https://travis-ci.org/) 會為每個你收到的 Pull Request 執行構建,就像每次提交也會觸發構建一樣。想了解更多關於 Travis CI 的訊息,請參考 [Travis CI入門](http://docs.travis-ci.com/user/getting-started/)。 287 | 288 | [![Travis CI status](https://cloud.githubusercontent.com/assets/1687642/2700187/3a88838c-c410-11e3-9a46-e65e2a0458cd.png)](https://github.com/octokit/octokit.rb/pull/452) 289 | 290 | [*進一步了解提交狀態 API.*](https://github.com/blog/1227-commit-status-api) 291 | 292 | ### Markdown 文件語法高亮 293 | 例如,可以像下面這樣在你的 Markdown 文件裡為 Ruby 代碼添加語法高亮: 294 | 295 | ```ruby 296 | require 'tabbit' 297 | table = Tabbit.new('Name', 'Email') 298 | table.add_row('Tim Green', 'tiimgreen@gmail.com') 299 | puts table.to_s 300 | ``` 301 | 302 | 效果如下: 303 | 304 | ```ruby 305 | require 'tabbit' 306 | table = Tabbit.new('Name', 'Email') 307 | table.add_row('Tim Green', 'tiimgreen@gmail.com') 308 | puts table.to_s 309 | ``` 310 | 311 | Github使用 [Linguist](https://github.com/github/linguist) 做語言識別和語法高亮。你可以仔細閱讀 [languages YAML file](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml),了解有哪些可用的關鍵字。 312 | 313 | [*進一步了解 GitHub Flavored Markdown.*](https://help.github.com/articles/github-flavored-markdown) 314 | 315 | ### 表情符號 316 | 317 | 可以在 Pull Requests, Issues, 提交消息, Markdown 文件裡加入表情符號。使用方法 `:name_of_emoji:` 318 | 319 | ``` 320 | :smile: 321 | ``` 322 | 將輸出一個笑臉: 323 | 324 | :smile: 325 | 326 | Github 支持的完整表情符號號列表詳見[emoji-cheat-sheet.com](http://www.emoji-cheat-sheet.com/) 或 [scotch-io/All-Github-Emoji-Icons](https://github.com/scotch-io/All-Github-Emoji-Icons)。 327 | 328 | Github 上使用最多的5個表情符號號是: 329 | 330 | 1. `:shipit:` 331 | 2. `:sparkles:` 332 | 3. `:-1:` 333 | 4. `:+1:` 334 | 5. `:clap:` 335 | 336 | ### 圖片 / GIF 動畫 337 | 註解和README等文件裡也可以使用圖片和 GIF 動畫: 338 | 339 | ``` 340 | ![Alt Text](http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif) 341 | ``` 342 | 343 | 倉庫中的圖片可以被直接引用: 344 | 345 | ``` 346 | ![Alt Text](https://github.com/{user}/{repo}/raw/master/path/to/image.gif) 347 | ``` 348 | 349 | ![Peter don't care](http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif) 350 | 351 | 所有圖片都緩存在 Github,不用擔心你的網站不能訪問時就看不到圖片了。 352 | 353 | #### 在 GitHub Wiki 中引用圖片 354 | 有多種方法可以在 Wiki 頁面裡嵌入圖片。既可以像上一條裡那樣使用標準的 Markdown 語法,也可以像下面這樣指定圖片的高度或寬度: 355 | 356 | ```markdown 357 | [[ http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif | height = 100px ]] 358 | ``` 359 | 結果: 360 | 361 | ![Just a screenshot](http://i.imgur.com/J5bMf7S.png) 362 | 363 | ### 快速引用 364 | 在主題評論中引用之前某個人所說的,只需選中文件,然後按 `r` 鍵,想要的就會以引用的形式複製到你的輸入框裡。 365 | 366 | ![Quick Quote](https://f.cloud.github.com/assets/296432/124483/b0fa6204-6ef0-11e2-83c3-256c37fa7abc.gif) 367 | 368 | [*進一步了解快速引用.*](https://github.com/blog/1399-quick-quotes) 369 | 370 | ### 複製貼上剪貼板中的圖片到評論 371 | 372 | _(僅適用於 Chrome 瀏覽器)_ 373 | 374 | 當截屏圖片複製到剪貼板後(mac 上用 `cmd-ctrl-shift-4`),你可以用(`cmd-v / ctrl-v`)把圖片複製貼上到評論框裡,然後它就會自動上傳到 Github。 375 | 376 | ![Pasting Clipboard Image to Comments](https://cloud.githubusercontent.com/assets/39191/5794265/39c9b65a-9f1b-11e4-9bc7-04e41f59ea5f.png) 377 | 378 | [*進一步了解在 issue 中使用附件*](https://help.github.com/articles/issue-attachments) 379 | 380 | 381 | ### 快速添加許可證文件 382 | 建立一個倉庫時,Github會為你提供一個預設的軟體授權條款: 383 | 384 | ![License](http://i.imgur.com/Chqj4Fg.png) 385 | 386 | 對於已有的倉庫,可以通過 web 界面建立文件來添加軟體授權條款。輸入`LICENSE`作為文件名後,同樣可以從預設的列表中選擇一個作為模板。 387 | 388 | ![License](http://i.imgur.com/fTjQict.png) 389 | 390 | 這個技巧也適用於 `.gitignore` 文件。 391 | 392 | [*進一步了解開源許可證*](https://help.github.com/articles/open-source-licensing) 393 | 394 | ### 任務列表 395 | Issues 和 Pull requests 裡可以添加複選框,語法如下(註意空白符): 396 | 397 | ``` 398 | - [ ] Be awesome 399 | - [ ] Prepare dinner 400 | - [ ] Research recipe 401 | - [ ] Buy ingredients 402 | - [ ] Cook recipe 403 | - [ ] Sleep 404 | ``` 405 | 406 | ![Task List](http://i.imgur.com/jJBXhsY.png) 407 | 408 | 當項目被選中時,它對應的 Markdown 原始碼也被更新了: 409 | 410 | ``` 411 | - [x] Be awesome 412 | - [ ] Prepare dinner 413 | - [x] Research recipe 414 | - [x] Buy ingredients 415 | - [ ] Cook recipe 416 | - [ ] Sleep 417 | ``` 418 | 419 | [*進一步了解任務列表.*](https://help.github.com/articles/writing-on-github#task-lists) 420 | 421 | #### Markdown 文件中的任務列表 422 | 423 | 在完全符合Markdown語法的文件中可以使用以下語法加入一個**只讀**的任務列表 424 | 425 | 426 | ``` 427 | - [ ] Mercury 428 | - [x] Venus 429 | - [x] Earth 430 | - [x] Moon 431 | - [x] Mars 432 | - [ ] Deimos 433 | - [ ] Phobos 434 | ``` 435 | 436 | - [ ] Mercury 437 | - [x] Venus 438 | - [x] Earth 439 | - [x] Moon 440 | - [x] Mars 441 | - [ ] Deimos 442 | - [ ] Phobos 443 | 444 | [*進一步了解 Markdown 文件中的任務列表*](https://github.com/blog/1825-task-lists-in-all-markdown-documents) 445 | 446 | ### 相對連接 447 | Markdown文件裡連接到內部內容時推薦使用相對連接。 448 | 449 | ```markdown 450 | [Link to a header](#awesome-section) 451 | [Link to a file](docs/readme) 452 | ``` 453 | 絕對連接會在 URL 改變時(例如重新命名倉庫、使用者名稱改變,建立分支項目)被更新。使用相對連接能夠保證你的文件不受此影響。 454 | 455 | [*進一步了解相對連接.*](https://help.github.com/articles/relative-links-in-readmes) 456 | 457 | ### GitHub Pages 的中繼資料與插件支持 458 | 在 Jekyll 頁面和文章裡,倉庫訊息可在 `site.github` 命名空間下找到,也可以顯示出來,例如,使用 `{{ site.github.project_title }}`顯示項目標題。 459 | 460 | Jemoji 和 jekyll-mentions 插件為你的 Jekyll 文章和頁面增加了[emoji](#emojis)和[@mentions](https://github.com/blog/821)功能。 461 | 462 | [*了解更多 GitHub Pages 的中繼資料和插件支持.*](https://github.com/blog/1797-repository-metadata-and-plugin-support-for-github-pages) 463 | 464 | ### 查看 YAML 格式的中繼資料 465 | 許多博客網站,比如基於 [Jekyll](http://jekyllrb.com/)的[GitHub Pages](http://pages.github.com/) ,都依賴於一些文章頭部的 YAML 格式的中繼資料。 Github 會將其渲染成一個水平表格,方便閱讀。 466 | 467 | ![YAML metadata](https://camo.githubusercontent.com/47245aa16728e242f74a9a324ce0d24c0b916075/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f36343035302f313232383236372f65303439643063362d323761302d313165332d396464382d6131636432323539393334342e706e67) 468 | 469 | [*進一步了解 在文件裡查看 YAML 中繼資料.*](https://github.com/blog/1647-viewing-yaml-metadata-in-your-documents) 470 | 471 | ### 渲染表格數據 472 | 473 | GitHub 支持將 `.csv` (逗號分隔)和 `.tsv` (定位點分隔)格式的文件渲染成表格數據。 474 | 475 | ![Tabular data](https://camo.githubusercontent.com/1b6dd0157ffb45d9939abf14233a0cb13b3b4dfe/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3238323735392f3937363436322f33323038336463652d303638642d313165332d393262322d3566323863313061353035392e706e67) 476 | 477 | [*進一步了解渲染表格數據.*](https://github.com/blog/1601-see-your-csvs) 478 | 479 | ### 撤銷 Pull Request 480 | 合併一個 Pull Request 之後,你可能會反悔:要麼是這次 Pull Request 沒什麼用處,要麼是還不到合併的時候。 481 | 482 | 此時可以通過 Pull Request 中的 Revert 按鈕來撤銷一個已合併的 Pull Request 中的 commit。按下按鈕後將自動生成一個進行逆操作的 Pull Request。 483 | 484 | ![Revert button](https://camo.githubusercontent.com/0d3350caf2bb1cba53123ffeafc00ca702b1b164/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f68656c702f70756c6c5f72657175657374732f7265766572742d70756c6c2d726571756573742d6c696e6b2e706e67) 485 | 486 | [*進一步了解「撤銷」按鈕](https://github.com/blog/1857-introducing-the-revert-button) 487 | 488 | ### Diffs 489 | #### 可渲染文件的Diffs 490 | 491 | Commit 和 Pull Request 裡包含有 Github 支持的可渲染文件(比如 Markdown)會提供*source* 和 *rendered* 兩個視圖功能。 492 | 493 | ![Source / Rendered view](https://github-images.s3.amazonaws.com/help/repository/rendered_prose_diff.png) 494 | 495 | 點擊 "rendered" 按鈕,看看改動在渲染後的顯示效果。當你添加、刪除或修改文件時,渲染純文件視圖非常方便。 496 | 497 | ![Rendered Prose Diffs](https://f.cloud.github.com/assets/17715/2003056/3997edb4-862b-11e3-90be-5e9586edecd7.png) 498 | 499 | [*進一步了解渲染純文件視圖Diffs.*](https://github.com/blog/1784-rendered-prose-diffs) 500 | 501 | #### 可比較的地圖數據 502 | 當你在GitHub上查看一個包含地理數據的 commit 或 pull request時,Github 將以可視化的方式比對版本之間的差異。 503 | 504 | [![Diffable Maps](https://f.cloud.github.com/assets/282759/2090660/63f2e45a-8e97-11e3-9d8b-d4c8078b004e.gif)](https://github.com/benbalter/congressional-districts/commit/2233c76ca5bb059582d796f053775d8859198ec5) 505 | 506 | [*進一步了解可比較的地圖數據.*](https://github.com/blog/1772-diffable-more-customizable-maps) 507 | 508 | #### 在 Diff 中展開查看更多的上下文 509 | 你可以通過點擊 diff 邊欄裡的 *unfold* 按鈕來多顯示幾行上下文。你可以一直點擊 *unfold* 按鈕直到顯示了文件的全部內容。這個功能在所有 GitHub 的 diff 功能中都可以使用。 510 | 511 | ![Expanding Context in Diffs](https://f.cloud.github.com/assets/22635/1610539/863c1f64-5584-11e3-82bf-151b406a272f.gif) 512 | 513 | [*進一步了解展開 Diff 上下文.*](https://github.com/blog/1705-expanding-context-in-diffs) 514 | 515 | #### 獲取 Pull Request 的 diff 或 patch 文件 516 | 在 Pull Request 的 URL 後面加上 `.diff` 或 `.patch` 的擴展名就可以得到它的 diff 或 patch 文件,例如: 517 | 518 | ``` 519 | https://github.com/tiimgreen/github-cheat-sheet/pull/15 520 | https://github.com/tiimgreen/github-cheat-sheet/pull/15.diff 521 | https://github.com/tiimgreen/github-cheat-sheet/pull/15.patch 522 | ``` 523 | `.diff` 擴展會使用普通文件格式顯示如下內容: 524 | 525 | ``` 526 | diff --git a/README.md b/README.md 527 | index 88fcf69..8614873 100644 528 | --- a/README.md 529 | +++ b/README.md 530 | @@ -28,6 +28,7 @@ All the hidden and not hidden features of Git and GitHub. This cheat sheet was i 531 | - [Merged Branches](#merged-branches) 532 | - [Quick Licensing](#quick-licensing) 533 | - [TODO Lists](#todo-lists) 534 | +- [Relative Links](#relative-links) 535 | - [.gitconfig Recommendations](#gitconfig-recommendations) 536 | - [Aliases](#aliases) 537 | - [Auto-correct](#auto-correct) 538 | @@ -381,6 +382,19 @@ When they are clicked, they will be updated in the pure Markdown: 539 | - [ ] Sleep 540 | 541 | (...) 542 | ``` 543 | #### 顯示圖片以及比較圖片 544 | GitHub 可以顯示包括 PNG、JPG、GIF、PSD 在內的多種圖片格式並提供了幾種方式來比較這些格式的圖片文件版本間的不同。 545 | 546 | [![Diffable PSD](https://cloud.githubusercontent.com/assets/2546/3165594/55f2798a-eb56-11e3-92e7-b79ad791a697.gif)](https://github.com/blog/1845-psd-viewing-diffing) 547 | 548 | [*查看更多關於圖片顯示和比較*](https://help.github.com/articles/rendering-and-diffing-images) 549 | 550 | ### Hub 551 | [Hub](https://github.com/github/hub) 是一個對 Git 進行了封裝的命令行工具,可以幫助你更方便的使用 Github。 552 | 553 | 例如可以像下面這樣進行複製: 554 | 555 | ```bash 556 | $ hub clone tiimgreen/toc 557 | ``` 558 | 559 | [*查看更多 Hub 提供的超酷命令.*](https://github.com/github/hub#commands) 560 | 561 | ### 貢獻者指南 562 | 563 | 在倉庫的根目錄添加一個名為 `CONTRIBUTING` 的文件後,貢獻者在新建 Issue 或 Pull Request 時會看到一個指向這個文件的連接。 564 | 565 | ![Contributing Guidelines](https://camo.githubusercontent.com/71995d6b0e620a9ef1ded00a04498241c69dd1bf/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f736b697463682f6973737565732d32303132303931332d3136323533392e6a7067) 566 | 567 | [*進一步了解貢獻者指南.*](https://github.com/blog/1184-contributing-guidelines) 568 | 569 | ### Octicons 570 | GitHubs 圖標庫 (Octicons) 現已開源。 571 | 572 | ![Octicons](https://og.github.com/octicons/octicons@1200x630.png) 573 | 574 | [*進一步了解 GitHub 圖標庫*](https://octicons.github.com) 575 | 576 | ### GitHub 資源 577 | | 內容 | 連接 | 578 | | ----- | ---- | 579 | | 探索 GitHub | https://github.com/explore | 580 | | GitHub 博客 | https://github.com/blog | 581 | | GitHub 幫助 | https://help.github.com/ | 582 | | GitHub 培訓 | http://training.github.com/ | 583 | | GitHub 開發者 | https://developer.github.com/ | 584 | 585 | #### GitHub 相關演講視頻 586 | | 內容 | 連接 | 587 | | ----- | ---- | 588 | | How GitHub Uses GitHub to Build GitHub | https://www.youtube.com/watch?v=qyz3jkOBbQY | 589 | | Introduction to Git with Scott Chacon of GitHub | https://www.youtube.com/watch?v=ZDR433b0HJY | 590 | | How GitHub No Longer Works | https://www.youtube.com/watch?v=gXD1ITW7iZI | 591 | | Git and GitHub Secrets | https://www.youtube.com/watch?v=Foz9yvMkvlA | 592 | | More Git and GitHub Secrets | https://www.youtube.com/watch?v=p50xsL-iVgU | 593 | 594 | ## Git 595 | ### 從工作區去除大量已刪除文件 596 | 當用 `/bin/rm` 命令刪除了大量文件之後,你可以用下面一條命令從工作區和索引中去除這些文件,以免一個一個的刪除: 597 | 598 | ```bash 599 | $ git rm $(git ls-files -d) 600 | ``` 601 | 602 | 例如: 603 | 604 | ```bash 605 | $ git status 606 | On branch master 607 | Changes not staged for commit: 608 | deleted: a 609 | deleted: c 610 | 611 | $ git rm $(git ls-files -d) 612 | rm 'a' 613 | rm 'c' 614 | 615 | $ git status 616 | On branch master 617 | Changes to be committed: 618 | deleted: a 619 | deleted: c 620 | ``` 621 | 622 | ### 上一個分支 623 | 快速檢出上一個分支: 624 | 625 | ```bash 626 | $ git checkout - 627 | # Switched to branch 'master' 628 | 629 | $ git checkout - 630 | # Switched to branch 'next' 631 | 632 | $ git checkout - 633 | # Switched to branch 'master' 634 | ``` 635 | 636 | [*進一步了解 Git 分支.*](http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging) 637 | 638 | ### 去除空白 639 | 640 | Git Stripspace 命令可以: 641 | 642 | - 去掉行尾空白符 643 | - 多個空行壓縮成一行 644 | - 必要時在文件末尾增加一個空行 645 | 646 | 使用此命令時必須傳入一個文件,像這樣: 647 | 648 | ```bash 649 | $ git stripspace < README.md 650 | ``` 651 | 652 | [*進一步了解 Git `stripspace` 命令.*](http://git-scm.com/docs/git-stripspace) 653 | 654 | ### SSH 金鑰 655 | 656 | 您可以藉由下面網址得到全部公開的 ssh 金鑰: 657 | 658 | ``` 659 | https://github.com/{user}.keys 660 | ``` 661 | 662 | 範例:[https://github.com/tiimgreen.keys](https://github.com/tiimgreen.keys) 663 | 664 | [*更多詳細 SSH 金鑰資訊...*](https://changelog.com/github-exposes-public-ssh-keys-for-its-users/) 665 | 666 | 667 | ### 檢出 Pull Requests 668 | 669 | 對 Github 倉庫來說,Pull Request 是種特殊分支, 可以通過以下多種方式取到本地: 670 | 671 | 取出某個特定的 Pull Request 並臨時作為本地的 `FETCH_HEAD` 中以便進行快速查看更改( diff )以及合併( merge ): 672 | 673 | ```bash 674 | $ git fetch origin refs/pull/[PR-Number]/head 675 | ``` 676 | 677 | 通過 refspec 獲取所有的 Pull Request 為本地分支: 678 | 679 | ```bash 680 | $ git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*' 681 | ``` 682 | 683 | 或在倉庫的 `.git/config` 中加入下列設置來自動獲取遠程倉庫中的 Pull Request 684 | ``` 685 | [remote "origin"] 686 | fetch = +refs/heads/*:refs/remotes/origin/* 687 | url = git@github.com:tiimgreen/github-cheat-sheet.git 688 | ``` 689 | 690 | ``` 691 | [remote "origin"] 692 | fetch = +refs/heads/*:refs/remotes/origin/* 693 | url = git@github.com:tiimgreen/github-cheat-sheet.git 694 | fetch = +refs/pull/*/head:refs/remotes/origin/pr/* 695 | ``` 696 | 697 | 對基於派生庫的 Pull Request,可以通過先 `checkout` 代表此 Pull Request 的遠端分支再由此分支建立一個本地分支: 698 | 699 | ```bash 700 | $ git checkout pr/42 pr-42 701 | ``` 702 | 703 | 操作多個倉庫的時候,可以在 Git 中設置獲取 Pull Request 的全局選項。 704 | 705 | ```bash 706 | git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*" 707 | ``` 708 | 709 | 此時可以在任意倉庫中使用以下命令: 710 | 711 | ```bash 712 | git fetch origin 713 | ``` 714 | 715 | ```bash 716 | git checkout pr/42 717 | ``` 718 | 719 | 720 | [*進一步了解如何本地檢出 pull request.*](https://help.github.com/articles/checking-out-pull-requests-locally) 721 | 722 | ### 沒有任何改動的提交 723 | 可以使用`--allow-empty`選項強製建立一個沒有任何改動的提交: 724 | 725 | ```bash 726 | $ git commit -m "Big-ass commit" --allow-empty 727 | ``` 728 | 729 | 這樣做在如下幾種情況下是有意義的: 730 | 731 | - 標記新的工作或一個新功能的開始。 732 | - 記錄對項目的跟代碼無關的改動。 733 | - 跟使用你倉庫的其他人交流。 734 | - 作為倉庫的第一次提交,因為第一次提交後不能被 rebase: `git commit -m "init repo" --allow-empty`. 735 | 736 | ### 美化 Git Status 737 | 在命令行輸入如下命令: 738 | 739 | ```bash 740 | $ git status 741 | ``` 742 | 743 | 可以看到: 744 | 745 | ![git status](http://i.imgur.com/qjPyvXb.png) 746 | 747 | 加上`-sb`選項: 748 | 749 | ```bash 750 | $ git status -sb 751 | ``` 752 | 753 | 這會得到: 754 | 755 | ![git status -sb](http://i.imgur.com/K0OY3nm.png) 756 | 757 | [*進一步了解 Git `status` 命令.*](http://git-scm.com/docs/git-status) 758 | 759 | ### 美化 Git Log 760 | 輸入如下命令: 761 | 762 | ```bash 763 | $ git log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative 764 | ``` 765 | 766 | 可以看到: 767 | 768 | ![git log --all --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative](http://i.imgur.com/58eOtkW.png) 769 | 770 | 這要歸功於 [Palesz](http://stackoverflow.com/users/88355/palesz) 在 stackoverflow 的回答。 771 | 772 | *這個命令可以被用作別名,詳細做法見[這裡](#git%E5%91%BD%E4%BB%A4%E8%87%AA%E5%AE%9A%E4%B9%89%E5%88%AB%E5%90%8D)。* 773 | 774 | [*進一步了解 Git `log` 命令.*](http://git-scm.com/docs/git-log) 775 | 776 | ### Git 查詢 777 | Git 查詢運行你在之前的所有提交訊息裡進行搜索,找到其中和搜索條件相匹配的最近的一條。 778 | 779 | ```bash 780 | $ git show :/query 781 | ``` 782 | 783 | 這裡 `query` (區別大小寫)是你想要搜索的詞語, 這條命令會找到包含這個詞語的最後那個提交並顯示變動詳情。 784 | 785 | ```bash 786 | $ git show :/typo 787 | ``` 788 | ![git show :/query](http://i.imgur.com/icaGiNt.png) 789 | 790 | * 按 `q` 鍵退出命令。* 791 | 792 | ### Git Grep 793 | 794 | Git Grep 將顯示匹配字串的行號。 795 | 796 | 執行: 797 | 798 | ```bash 799 | $ git grep aliases 800 | ``` 801 | 會找出檔案內有出現 *aliases* 字串。 802 | 803 | ![git grep aliases](http://i.imgur.com/DL2zpQ9.png) 804 | 805 | * 按 `q` 結束搜尋* 806 | 807 | 你也可以使用多重 flags 來達到進階搜尋。範例: 808 | 809 | * `-e` 下一個搜尋匹配條件 (e.g. regex) 810 | * `--and`, `--or` and `--not` 合併多重匹配字串. 811 | 812 | 使用如下: 813 | ```bash 814 | $ git grep -e pattern --and -e anotherpattern 815 | ``` 816 | 817 | [*更多詳細 Git `grep` 指令介紹*](http://git-scm.com/docs/git-grep) 818 | 819 | ### 合併分支 820 | 821 | 輸入命令: 822 | 823 | ```bash 824 | $ git branch --merged 825 | ``` 826 | 827 | 這會顯示所有已經合併到你當前分支的分支列表。 828 | 829 | 相反地: 830 | 831 | ```bash 832 | $ git branch --no-merged 833 | ``` 834 | 835 | 會顯示所有還沒有合併到你當前分支的分支列表。 836 | 837 | [*進一步了解 Git `branch` 命令.*](http://git-scm.com/docs/git-branch) 838 | 839 | ### 修復有問題的提交以及自動合併 840 | 如果上一個或多個提交包含了錯誤,可以在你修復問題後使用下列命令處理(假設要修復的提交版本是`abcde`): 841 | ```bash 842 | $ git commit --fixup=abcde 843 | $ git rebase abcde^ --autosquash -i 844 | ``` 845 | [*進一步了解 Git `commit` 命令.*](http://git-scm.com/docs/git-commit) 846 | [*進一步了解 Git `rebase` 命令.*](http://git-scm.com/docs/git-rebase) 847 | 848 | ### 以網站方式查看本地倉庫 849 | 使用 Git 的 `instaweb` 可以立即在 `gitweb` 中瀏覽你的工作倉庫。這個命令是個簡單的腳本,設置了 `gitweb` 和用來瀏覽本地倉庫的Web服務器。*(譯者註:默認需要lighttpd支持)* 850 | 851 | ```bash 852 | $ git instaweb 853 | ``` 854 | 855 | 執行後打開: 856 | 857 | ![Git instaweb](http://i.imgur.com/Dxekmqc.png) 858 | 859 | [*進一步了解 Git `instaweb` 命令.*](http://git-scm.com/docs/git-instaweb) 860 | 861 | ### Git 設置 862 | 所有 Git 設置都保存在你的 `.gitconfig` 文件中。 863 | 864 | #### Git 命令自定義別名 865 | 別名用來幫助你定義自己的 git 命令。比如你可以定義 `git a` 來運行 `git add --all`。 866 | 867 | 要添加一個別名, 一種方法是打開 `~/.gitconfig` 文件並添加如下內容: 868 | 869 | ``` 870 | [alias] 871 | co = checkout 872 | cm = commit 873 | p = push 874 | # Show verbose output about tags, branches or remotes 875 | tags = tag -l 876 | branches = branch -a 877 | remotes = remote -v 878 | ``` 879 | 880 | ...或者在命令行裡鍵入: 881 | 882 | ```bash 883 | $ git config --global alias.new_alias git_function 884 | ``` 885 | 886 | 例如: 887 | 888 | ```bash 889 | $ git config --global alias.cm commit 890 | ``` 891 | 892 | 指向多個命令的別名可以用引號來定義: 893 | 894 | ```bash 895 | $ git config --global alias.ac 'add -A . && commit' 896 | ``` 897 | 898 | 下面列出了一些有用的別名: 899 | 900 | | 別名 Alias | 命令 Command | 如何設置 What to Type | 901 | | --- | --- | --- | 902 | | `git cm` | `git commit` | `git config --global alias.cm commit` | 903 | | `git co` | `git checkout` | `git config --global alias.co checkout` | 904 | | `git ac` | `git add . -A` `git commit` | `git config --global alias.ac '!git add -A && git commit'` | 905 | | `git st` | `git status -sb` | `git config --global alias.st 'status -sb'` | 906 | | `git tags` | `git tag -l` | `git config --global alias.tags 'tag -l'` | 907 | | `git branches` | `git branch -a` | `git config --global alias.branches 'branch -a'` | 908 | | `git cleanup` | `git branch --merged \| grep -v '*' \| xargs git branch -d` | `git config --global alias.cleanup "!git branch --merged \| grep -v '*' \| xargs git branch -d"` | 909 | | `git remotes` | `git remote -v` | `git config --global alias.remotes 'remote -v'` | 910 | | `git lg` | `git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --` | `git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"` | 911 | 912 | #### 自動更正 913 | 如果鍵入 `git comit` 你會看到如下輸出: 914 | 915 | ```bash 916 | $ git comit -m "Message" 917 | # git: 'comit' is not a git command. See 'git --help'. 918 | 919 | # Did you mean this? 920 | # commit 921 | ``` 922 | 923 | 為了在鍵入 `comit` 調用 `commit`命令,隻需啟用自動糾錯功能: 924 | 925 | ```bash 926 | $ git config --global help.autocorrect 1 927 | ``` 928 | 929 | 現在你就會看到: 930 | 931 | ```bash 932 | $ git comit -m "Message" 933 | # WARNING: You called a Git command named 'comit', which does not exist. 934 | # Continuing under the assumption that you meant 'commit' 935 | # in 0.1 seconds automatically... 936 | ``` 937 | 938 | #### 顏色輸出 939 | 要在你的 Git 命令輸出裡加上顏色的話,可以用如下命令: 940 | 941 | ```bash 942 | $ git config --global color.ui 1 943 | ``` 944 | 945 | [*進一步了解 Git `config` 命令.*](http://git-scm.com/docs/git-config) 946 | 947 | ### Git 資源 948 | | Title | Link | 949 | | ----- | ---- | 950 | | Official Git Site | http://git-scm.com/ | 951 | | Official Git Video Tutorials | http://git-scm.com/videos | 952 | | Code School Try Git | http://try.github.com/ | 953 | | Introductory Reference & Tutorial for Git | http://gitref.org/ | 954 | | Official Git Tutorial | http://git-scm.com/docs/gittutorial | 955 | | Everyday Git | http://git-scm.com/docs/everyday | 956 | | Git Immersion | http://gitimmersion.com/ | 957 | | Git for Computer Scientists | http://eagain.net/articles/git-for-computer-scientists/ | 958 | | Git Magic | http://www-cs-students.stanford.edu/~blynn/gitmagic/ | 959 | | GitHub Training Kit | http://training.github.com/kit | 960 | | Git Visualization Playground | http://onlywei.github.io/explain-git-with-d3/#freeplay | 961 | 962 | #### Git 參考書籍 963 | | Title | Link | 964 | | ----- | ---- | 965 | | Pragmatic Version Control Using Git | http://www.pragprog.com/titles/tsgit/pragmatic-version-control-using-git | 966 | | Pro Git | http://git-scm.com/book | 967 | | Git Internals Pluralsight | https://github.com/pluralsight/git-internals-pdf | 968 | | Git in the Trenches | http://cbx33.github.com/gitt/ | 969 | | Version Control with Git | http://www.amazon.com/Version-Control-Git-collaborative-development/dp/1449316387 | 970 | | Pragmatic Guide to Git | http://www.pragprog.com/titles/pg_git/pragmatic-guide-to-git | 971 | | Git: Version Control for Everyone | http://www.packtpub.com/git-version-control-for-everyone/book | 972 | --------------------------------------------------------------------------------