Salta ai contenuti

Tig (Text-mode Interface for Git) Cheatsheet

Tig (Text-mode Interface for Git) Cheatsheet

Installation

PlatformCommand
Ubuntu/Debiansudo apt update && sudo apt install tig
Fedora/RHELsudo dnf install tig
Arch Linuxsudo pacman -S tig
macOS (Homebrew)brew install tig
macOS (MacPorts)sudo port install tig
Windows (Git Bash)Included with Git for Windows
Windows (WSL)sudo apt install tig
Windows (Scoop)scoop install tig
From Sourcegit clone https://github.com/jonas/tig.git && cd tig && make && sudo make install
Verify Installation: tig --version

Basic Commands

CommandDescription
tigOpen main view showing commit history in current repository
tig statusShow working directory status (like git status)
tig blame <file>Show line-by-line authorship for a file
tig <file>Show commit history for a specific file
tig show <commit>Display details of a specific commit
tig refsShow all branches and tags
tig stashDisplay all stashed changes
tig logShow commit log view
tig diffShow unstaged changes in working directory
tig grep <pattern>Search for pattern in repository
tig <branch>Show commits from a specific branch
tig --allShow commits from all branches
tig --helpDisplay help information
tig --versionShow tig version information
KeyDescription
j / Move down one line
k / Move up one line
h / Scroll left
l / Scroll right
PgUp / bPage up
PgDn / SpacePage down
HomeJump to first line
EndJump to last line
EnterOpen/select item (context-dependent)
TabSwitch to next view
qClose current view
QClose all views and quit
RReload/refresh current view
OMaximize current view
hShow help and key bindings

Search and Filter Keys

KeyDescription
/Search forward
?Search backward
nFind next match
NFind previous match
[Jump to previous diff chunk
]Jump to next diff chunk
{Jump to previous file in diff
}Jump to next file in diff

Advanced Commands

CommandDescription
tig --author="Name"Filter commits by specific author
tig --since="2 weeks ago"Show commits from a relative date
tig --after="2024-01-01" --before="2024-12-31"Show commits within date range
tig --grep="pattern"Show commits with pattern in message
tig --mergesShow only merge commits
tig --no-mergesExclude merge commits
tig main..featureShow commits in feature not in main
tig main...featureShow commits that differ between branches
tig --follow -- <file>Track file history through renames
tig -S"function_name"Pickaxe search: commits changing occurrences
tig -G"regex"Show commits where diff matches regex
tig -n 100Limit to last 100 commits
tig -- '*.py'Show commits affecting Python files only
tig reflogBrowse Git reflog entries
tig show <commit>:<path>Display file content at specific commit
tig blame +<line> <file>Open blame view at specific line number

Interactive Operations (Inside Tig)

KeyViewDescription
ustatusStage/unstage file or chunk
1statusStage/unstage single line
!statusRevert file or chunk
CstatusCommit staged changes
Cmain/logCherry-pick commit
emain/logEdit commit message (if HEAD)
!main/logRevert commit
@main/logMove to commit (checkout)
CrefsCreate new branch
drefsDelete branch
mrefsMerge branch
!anyExecute external command
:anyExecute git command (e.g., :!git reset)

Configuration

Tig reads configuration from these locations (in priority order):

  1. $XDG_CONFIG_HOME/tig/config (typically ~/.config/tig/config)
  2. ~/.tigrc
  3. $GIT_DIR/tigrc (repository-specific)
  4. /etc/tigrc (system-wide)

Creating Configuration File

# Create user config directory and file
mkdir -p ~/.config/tig
touch ~/.config/tig/config

# Or use traditional location
touch ~/.tigrc

Color Customization

# 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

View Settings

# 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 = ~

Diff Configuration

# 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

Custom Key Bindings

# 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)

Display Options

# 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

Common Use Cases

Use Case 1: Code Review Workflow

# 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

Use Case 2: Finding When a Bug Was Introduced

# 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

Use Case 3: Interactive Staging and Committing

# 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

Use Case 4: Exploring Project History

# 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

Use Case 5: Branch Management

# 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

Best Practices

  • Learn keyboard shortcuts: Tig is designed for keyboard navigation. Memorize j/k for movement, Enter to drill down, and q to go back for efficient browsing.

  • Use view-specific commands: Different views have different operations. Press h in any view to see available key bindings for that context.

  • Customize your configuration: Create a ~/.config/tig/config file to customize colors, bindings, and view settings to match your workflow and preferences.

  • Combine with Git commands: Use tig for visualization and Git commands for operations. Tig complements Git rather than replacing it.

  • Use filters for large repositories: In repositories with thousands of commits, use --author, --since, --grep, or file filters to narrow results.

  • Leverage the status view: Use tig status as an interactive alternative to git add -p for granular staging control.

  • Explore with Tab: Use Tab to cycle through related views and see different perspectives on the same data (commit → diff → tree).

  • Set up repository-specific configs: Create .git/tigrc in repositories that need special settings without affecting your global configuration.

Troubleshooting

IssueSolution
Tig not found after installationEnsure tig is in your PATH: which tig. Restart terminal or run source ~/.bashrc
Colors not displaying correctlyCheck terminal supports 256 colors. Set TERM=xterm-256color or configure colors in ~/.tigrc
Slow performance in large reposUse filters to limit commits: tig -n 1000 or tig --since="1 month ago". Consider set refresh-mode = manual
UTF-8 characters display incorrectlySet locale: export LC_ALL=en_US.UTF-8 and export LANG=en_US.UTF-8 in shell config
Mouse not workingEnable in config: set mouse = yes. Ensure terminal supports mouse events
Can’t edit commits or stage filesEnsure you have write permissions and are in a valid Git repository. Check git status works
Custom key bindings not workingVerify syntax in config file. Check for conflicts with default bindings. Reload with R
Tig crashes on startupCheck Git repository is valid: git status. Update tig to latest version. Remove custom config temporarily
Diff view shows binary filesAdd to .gitattributes: *.bin -diff. Or set set diff-options = --no-binary
Line numbers not showingEnable in config: set line-number-interval = 1 and ensure view supports line numbers

Quick Reference Card

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