Docu review done: Thu 29 Jun 2023 12:34:21 CEST

Table of Content

General

Tig is an ncurses-based text-mode interface for git. It functions mainly as a Git repository browser, but can also assist in staging changes for commit at chunk level and act as a pager for output from various Git commands.

Installation

Debian

$ apt install tig

Configuration

the configuration of tig has its own man page tigrc which contains samples of configuration snippes and so on

There are several places to store the coniguration for tig:

  • $XDG_CONFIG_HOME/tig/config
  • ~/.config/tig/config
  • ~/.tigrc
  • /etc/tigrc

You can also place your tig configuration inside of git configs:

  • $GIT_DIR/config
  • ~/.gitconfig
  • /etc/gitconfig

If you have tig complied on your own and added the readline support, then you get also a command and search history file. If you have it installed via apt you will get tig with readline support enabled.

Locations:

  • $XDG_DATA_HOME/tig/history
  • ~/.local/share/tig/history
  • ~/.tig_history

The location of the history file is determined in the following way. If $XDG_DATA_HOME is set and $XDG_DATA_HOME/tig/ exists, store history to $XDG_DATA_HOME/tig/history. If $XDG_DATA_HOME is empty or undefined, store history to ~/.local/share/tig/history, if the directory ~/.local/share/tig/ exists. Fall back to ~/.tig_history if ~/.local/share/tig/ does not exist.

If you add your tig configuration into your git config file, it follows the same style guied as the git configuration:

[tig]
    commit-order = topo
    line-graphics = yes
    tab-size = 4
    main-view-date-local = true

You can also add your own keybindings inside of the config file:

[tig "bind"]
    generic = P !git push
    generic = p !git plr
    generic = S :source ~/.gitconfig
    generic = 9 !echo -n "%(commit)" | xclip -selection c
    status = + !git commit --amend

Commands

If you just run tig without any parameter, the ncurses gui will open and start do display you the git log. But of course it has some very usefull parmeters, to make your live easier.

CommandDescription
blameShow given file annotated by commits. Takes zero or more git-blame options. Optionally limited from given revision.
statusStartup in status view, close to git-status
reflogStart up in reflog view
refsStart up in refs view. All refs are displayed unless limited by using one of the --branches, --remotes, or --tags parameters.
stashStart up in stash view
grep [pattern]Open the grep view. Supports the same options as git-grep.

Samples

These samples can be also looked at man tig

CommandDescription
tig test masterDisplay commits from one or more branches
tig --allPretend as if all the refs in refs/ are listed on the command line
tig test..masterDisplay differences between two branches
tig --submoduleDisplay changes for sub-module versions
tig -- READMEDisplay changes for a single file
tig READMEDisplay changes for a single file
tig show tig-0.8:READMEDisplay contents of the README file in a specific revision
tig --after="2004-01-01" --before="2006-05-16" -- READMEDisplay revisions between two dates for a specific file
tig blame -C READMEBlame file with copy detection enabled
tig --word-diff=plainUse word diff in the diff view

Keybindings

To interact with tig it offers you a bunch of keybindings.

To create own keybindings, have a look at the config section

These are just a small list what it can do, but which I use on a regulare base:

SekctionKeyDescription
General
hdisplays the help (also shows your custom bindings)
ENTERenter and open selected line
eopens file (on selected line) in editor
qcloses current view/section/…, closes tig if you are back to the started view
Qcloses tig always
Views
dopens diff view
j/kmove down/up
gallows you to perform git-grep and displays result
Xtoggles column of short commit ids in main view
Search
/let you search in the current view (like it odes in vim)
?let you search-back in the current view (like it odes in vim)
nfind next
Nfind previous

If you have opened a view at the same time with a diff (in split mode), the j/k will move your cursor in the diff section. But you can still navigate in the original view as well, just use your arrow keys (up and down). The diff view will stay and update the content to the selected line.

e.g. you are in the main view, presse ENTER to open the diff for the last commit and then press arrow down, now you will get the diff displayed for the second last commit.