Vai al contenuto

Tig (Text-mode Interface for Git) Cheatsheet

Installazione

Tabella_136_ Verificare l'installazione

Comandi di base

Tabella_137_

Keys di navigazione (Inside Tig)

Tabella_138_

Cerca e filtra le chiavi

Tabella_139_

Comandi avanzati

TABELLA: 140_

Operazioni interattive (Inside Tig)

Tabella_141_

Configurazione

Tig legge la configurazione da queste posizioni (in ordine prioritario):

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

Creare Configuration File

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

# Or use traditional location
touch ~/.tigrc

Personalizzazione del colore

# 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

Visualizzare le impostazioni

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

# 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 Cessioni chiave

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

Opzioni di visualizzazione

# 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

Migliori Pratiche

Traduzione: Tig è progettato per la navigazione della tastiera. Memorize j/k__ per il movimento, Enter per la perforazione, e q per tornare indietro per una navigazione efficiente.

Utilizza comandi specifici per la visualizzazione: diverse visualizzazioni hanno diverse operazioni. Premere h in qualsiasi modo per vedere i binding chiave disponibili per tale contesto.

  • Customizzare la configurazione: Creare un file ~/.config/tig/config__ per personalizzare colori, binding e visualizzare le impostazioni per abbinare il flusso di lavoro e le preferenze.

  • Combina con comandi Git: Utilizzare tig per la visualizzazione e comandi Git per le operazioni. Tig complementi Git piuttosto che sostituirlo.

  • Utilizza filtri per grandi repository: Nei repository con migliaia di commit, utilizzare --author, --since, --grep_, o filtri file per risultati ristretti.

  • Lasciare la vista sullo stato. Utilizzare tig status come alternativa interattiva a git add -p per il controllo granulare della stadiazione.

  • Explore with Tab: Usa Tab per andare in bicicletta attraverso viste correlate e vedere prospettive diverse sugli stessi dati (commettere → diff → albero).

  • Set up repository-specific configs: Crea .git/tigrc_ in repository che necessitano di impostazioni speciali senza compromettere la configurazione globale.

Risoluzione dei problemi

Tabella_142_

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