Tig (Gitのテキストモードインターフェース) チートシート
インストール
| プラットフォーム | コマンド |
|---|
| Ubuntu/Debian | sudo apt update && sudo apt install tig |
| Fedora/RHEL | sudo dnf install tig |
| Arch Linux | sudo pacman -S tig |
| macOS (Homebrew) | brew install tig |
| macOS (MacPorts) | sudo port install tig |
| Windows (Git Bash) | Windows 用 Git に同梱 |
| Windows (WSL) | sudo apt install tig |
| Windows (Scoop) | scoop install tig |
| From Source | git clone https://github.com/jonas/tig.git && cd tig && make && sudo make install |
インストールの確認: tig --version | |
基本コマンド
| コマンド | 説明 |
|---|
tig | 現在のリポジトリのコミット履歴を表示するメインビューを開く |
tig status | Show working directory status (like git status) |
tig blame <file> | ファイルの行単位の作者情報を表示する |
tig <file> | 特定のファイルのコミット履歴を表示 |
tig show <commit> | 特定のコミットの詳細を表示 |
tig refs | すべてのブランチとタグを表示 |
tig stash | すべてのスタッシュされた変更を表示 |
tig log | コミットログビューを表示 |
tig diff | 作業ディレクトリ内の未ステージの変更を表示 |
tig grep <pattern> | リポジトリでパターンを検索 |
tig <branch> | 特定のブランチからコミットを表示 |
tig --all | すべてのブランチからコミットを表示 |
tig --help | ヘルプ情報を表示 |
tig --version | Tigのバージョン情報を表示 |
ナビゲーションキー (Tig内)
| キー | 説明 |
|---|
j / ↓ | 1行下に移動 |
k / ↑ | 1行上に移動 |
h / ← | 左にスクロール |
l / → | 右にスクロール |
PgUp / b | ページアップ |
PgDn / Space | ページダウン |
Home | 最初の行にジャンプ |
End | 最終行にジャンプ |
Enter | アイテムを開く/選択(コンテキストに依存) |
Tab | 次のビューに切り替え |
q | 現在のビューを閉じる |
Q | すべてのビューを閉じて終了 |
R | 現在のビューをリロード/更新 |
O | 現在のビューを最大化 |
h | ヘルプとキーバインディングを表示 |
検索とフィルターキー
| キー | 説明 |
|---|
/ | 前方を検索 |
? | 後方検索 |
n | 次の一致を見つける |
N | 前の一致を検索 |
[ | 前の差分チャンクにジャンプ |
] | 次のdiffチャンクにジャンプ |
{ | diffで前のファイルにジャンプ |
} | diffで次のファイルにジャンプ |
高度なコマンド
| コマンド | 説明 |
|---|
tig --author="Name" | 特定の作成者によるコミットをフィルタリング |
tig --since="2 weeks ago" | 相対的な日付からコミットを表示 |
tig --after="2024-01-01" --before="2024-12-31" | 日付範囲内のコミットを表示 |
tig --grep="pattern" | メッセージにパターンを含むコミットを表示 |
tig --merges | マージコミットのみを表示 |
tig --no-merges | マージコミットを除外 |
tig main..feature | feature にあり、main にない commits を表示 |
tig main...feature | ブランチ間で異なるコミットを表示 |
tig --follow -- <file> | ファイル名の変更を通じてファイル履歴を追跡する |
tig -S"function_name" | ピッカーサーチ: コミットの変更箇所 |
tig -G"regex" | コミットを表示(diff が正規表現に一致するもの) |
tig -n 100 | 最後の100コミットに制限 |
tig -- '*.py' | Pythonファイルのみに影響するコミットを表示 |
tig reflog | Gitの履歴ログエントリを参照する |
tig show <commit>:<path> | 特定のコミット時のファイルの内容を表示 |
tig blame +<line> <file> | 特定の行番号でブレイム表示を開く |
インタラクティブ操作 (Tig内)
| キー | 表示 | 説明 |
|---|
u | ステータス | ファイルまたはチャンクのステージ/アンステージ |
1 | ステータス | 1行のステージング/アンステージ |
! | ステータス | ファイルまたはチャンクを元に戻す |
C | ステータス | ステージングされた変更をコミット |
C | メイン/ログ | チェリーピック commit |
e | メイン/ログ | コミットメッセージを編集 (HEADの場合) |
! | メイン/ログ | コミットを元に戻す |
@ | メイン/ログ | コミットに移動(チェックアウト) |
C | refs | 新しいブランチを作成 |
d | refs | ブランチを削除 |
m | refs | ブランチをマージ |
! | any | 外部コマンドを実行 |
: | any | Execute git command (e.g., :!git reset) |
設定
Tigは以下の場所から設定を読み取ります(優先順位順):
$XDG_CONFIG_HOME/tig/config``~/.config/tig/config(通常 ~/.tigrc)`$GIT_DIR/tigrc“/etc/tigrc````bash
Create user config directory and file
mkdir -p ~/.config/tig
touch ~/.config/tig/config
Or use traditional location
touch ~/.tigrc
# Customize interface colors
color cursor white blue bold
color title-focus white blue bold
color title-blur white black bold
# Diff colors
color diff-header yellow default
color diff-chunk magenta default
color diff-add green default
color diff-del red default
# Status colors
color stat-staged green default
color stat-unstaged red default
color stat-untracked yellow default
```(リポジトリ固有)```bash
# Configure main view columns
set main-view = id:yes date:default author:full commit-title:yes,graph:yes,refs:yes
# Set commit ID width
set id-width = 10
# Enable line numbers in blame view
set blame-view = date:default author:full id:yes,color line-number:yes,interval=1 text
# Line number display interval
set line-number-interval = 5
# Horizontal scrolling percentage
set horizontal-scroll = 33%
# Tab size for display
set tab-size = 4
# Truncation indicator
set truncation-delimiter = ~
``````bash
# Number of context lines in diffs
set diff-context = 3
# Ignore whitespace (options: no, all, some, at-eol)
set ignore-space = some
# Use patience diff algorithm
set diff-options = --patience
# Show untracked files in status view
set status-show-untracked-files = yes
```(システム全体)
### 設定ファイルの作成
```bash
# Bind 'C' in main view to cherry-pick
bind main C !git cherry-pick %(commit)
# Bind 'P' in status view to push
bind status P !git push
# Bind 'F' to fetch in main view
bind main F !git fetch
# Bind 'S' to create stash
bind status S !git stash save "%(prompt Enter stash message: )"
# Bind 'A' to amend commit
bind status A !git commit --amend
# Open commit in browser (GitHub)
bind main B !@hub browse -- commit/%(commit)
```
### カラーのカスタマイズ
```bash
# Wrap long lines
set wrap-lines = yes
# Show changes in status view
set status-show-untracked-dirs = yes
# Refresh interval (seconds)
set refresh-mode = auto
set refresh-interval = 1
# Mouse support
set mouse = yes
# Editor for commit messages
set editor-line-number = yes
```
### ビュー設定
```bash
# Open repository
tig
# Navigate to commit (use j/k)
# Press Enter to see full diff
# Press Tab to switch between views
# Press q to go back
# Review specific branch
tig feature-branch
# Compare branches
tig main..feature-branch
```### ユースケース 2: バグが導入されたタイミングの特定
```bash
# Search for specific code change
tig -S"problematic_function"
# Or search commit messages
tig --grep="bug\|fix" -i
# View blame for specific file
tig blame src/buggy-file.js
# Navigate to suspicious line
# Press Enter to see the commit
# Press Tab to see full commit details
```### ユースケース 3: インタラクティブなステージングとコミット
```bash
# Open status view
tig status
# Navigate to files (j/k)
# Press 'u' to stage/unstage files
# Press '1' to stage individual lines
# Press 'C' to commit when ready
# Write commit message and save
```### ユースケース 4: プロジェクト履歴の探索
```bash
# View all commits with graph
tig --all
# Filter by author and date
tig --author="John Doe" --since="1 month ago"
# View commits affecting specific files
tig -- src/core/*.py
# Follow file through renames
tig --follow -- src/renamed-file.js
```### ユースケース 5: ブランチ管理
```bash
# View all branches and tags
tig refs
# Navigate to branch
# Press 'C' to create new branch
# Press 'd' to delete branch
# Press 'm' to merge branch
# Press Enter to view branch commits
```## ベストプラクティス
- **キーボードショートカットを学ぶ**: Tigはキーボードナビゲーション用に設計されています。効率的な閲覧のために、`j/k`で移動、`Enter`でドリルダウン、`q`で戻るショートカットを覚えましょう。
- **ビュー固有のコマンドを使用**: 異なるビューには異なる操作があります。任意のビューで`h`を押すと、そのコンテキストで利用可能なキーバインディングが表示されます。
- **設定をカスタマイズ**: `~/.config/tig/config`ファイルを作成して、カラー、バインディング、ビュー設定をワークフローと好みに合わせてカスタマイズします。
- **Gitコマンドと組み合わせる**: 可視化にはtigを、操作にはGitコマンドを使用します。TigはGitを置き換えるのではなく、補完します。
- **大規模リポジトリでフィルターを使用**: コミット数が数千の場合、`--author`、`--since`、`--grep`、またはファイルフィルターを使用して結果を絞り込みます。
- **ステータスビューを活用**: `tig status`を`git add -p`の対話的な代替として使用し、細かいステージング制御を行います。
- **タブで探索**: `Tab`を使用して関連するビュー間を循環し、同じデータの異なる視点を確認します(コミット → 差分 → ツリー)。
- **リポジトリ固有の設定**: グローバル設定に影響を与えずに特別な設定が必要なリポジトリに`.git/tigrc`を作成します。
## トラブルシューティング
| 問題 | ソリューション |
|-------|----------|
| Tig not found after installation | Ensure tig is in your PATH: `which tig`. Restart terminal or run `source ~/.bashrc` |
| Colors not displaying correctly | Check terminal supports 256 colors. Set `TERM=xterm-256color` or configure colors in `~/.tigrc` |
| Slow performance in large repos | Use filters to limit commits: `tig -n 1000` or `tig --since="1 month ago"`. Consider `set refresh-mode = manual` |
| UTF-8 characters display incorrectly | Set locale: `export LC_ALL=en_US.UTF-8` and `export LANG=en_US.UTF-8` in shell config |
| Mouse not working | Enable in config: `set mouse = yes`. Ensure terminal supports mouse events |
| Can't edit commits or stage files | Ensure you have write permissions and are in a valid Git repository. Check `git status` works |
| Custom key bindings not working | Verify syntax in config file. Check for conflicts with default bindings. Reload with `R` |
| Tig crashes on startup | Check Git repository is valid: `git status`. Update tig to latest version. Remove custom config temporarily |
| Diff view shows binary files | Add to `.gitattributes`: `*.bin -diff`. Or set `set diff-options = --no-binary` |
| Line numbers not showing | Enable in config: `set line-number-interval = 1` and ensure view supports line numbers |
## クイックリファレンスカード```
LAUNCHING TIG NAVIGATION OPERATIONS
tig j/k ↓/↑ Move u Stage/unstage
tig status h/l ←/→ Scroll C Commit/cherry-pick
tig blame <file> PgUp/PgDn Page ! Revert/execute
tig <branch> Enter Select e Edit
tig --all Tab Next view @ Checkout
q/Q Quit R Refresh
SEARCH VIEWS FILTERS
/ Search forward tig Main --author="Name"
? Search backward tig status Status --since="date"
n Next match tig refs Branches --grep="pattern"
N Previous match tig blame Blame --no-merges
[ Prev chunk tig stash Stash -- '*.ext'
] Next chunk tig diff Diff
```