Add example user-defined commands to the manual
[tig.git] / manual.txt
blob5bfb2200a25503ba31eb9d82ab23f211aeece626
1 ifndef::doctype-manpage[]
2 The tig Manual
3 ==============
4 Jonas Fonseca <fonseca@diku.dk>
5 endif::doctype-manpage[]
7 This is the manual for tig, the ncurses-based text-mode interface for git.
8 Tig allows you to browse changes in a git repository and can additionally act
9 as a pager for output of various git commands. When used as a pager, it will
10 display input from stdin and colorize it.
12 When browsing repositories, tig uses the underlying git commands to present
13 the user with various views, such as summarized commit log and showing the
14 commit with the log message, diffstat, and the diff.
16 ifndef::backend-docbook[]
17 *Table of Contents*
19 include::manual.toc[]
20 endif::backend-docbook[]
22 [[calling-conventions]]
23 Calling Conventions
24 -------------------
26 [[pager-mode]]
27 Pager Mode
28 ~~~~~~~~~~
30 If stdin is a pipe, any log or diff options will be ignored and the pager view
31 will be opened loading data from stdin. The pager mode can be used for
32 colorizing output from various git commands.
34 Example on how to colorize the output of git-show(1):
36 -----------------------------------------------------------------------------
37 $ git show | tig
38 -----------------------------------------------------------------------------
40 [[cmd-options]]
41 Git Command Options
42 ~~~~~~~~~~~~~~~~~~~
44 All git command options specified on the command line will be passed to the
45 given command and all will be shell quoted before they are passed to the
46 shell.
48 NOTE: If you specify options for the main view, you should not use the
49 `--pretty` option as this option will be set automatically to the format
50 expected by the main view.
52 Example on how to view a commit and show both author and committer
53 information:
55 -----------------------------------------------------------------------------
56 $ tig show --pretty=fuller
57 -----------------------------------------------------------------------------
59 See the section on <<refspec, specifying revisions>> for an introduction to
60 revision options supported by the git commands. For details on specific git
61 command options, refer to the man page of the command in question.
63 [[viewer]]
64 The Viewer
65 ----------
67 The display consists of a status window on the last line of the screen and one
68 or more views. The default is to only show one view at a time but it is
69 possible to split both the main and log view to also show the commit diff.
71 If you are in the log view and press 'Enter' when the current line is a commit
72 line, such as:
74 -----------------------------------------------------------------------------
75 commit 4d55caff4cc89335192f3e566004b4ceef572521
76 -----------------------------------------------------------------------------
78 You will split the view so that the log view is displayed in the top window
79 and the diff view in the bottom window. You can switch between the two views
80 by pressing 'Tab'. To maximize the log view again, simply press 'l'.
82 [[views]]
83 Views
84 ~~~~~
86 Various 'views' of a repository are presented. Each view is based on output
87 from an external command, most often 'git log', 'git diff', or 'git show'.
89 The main view::
90         Is the default view, and it shows a one line summary of each commit
91         in the chosen list of revisions. The summary includes commit date,
92         author, and the first line of the log message. Additionally, any
93         repository references, such as tags, will be shown.
95 The log view::
96         Presents a more rich view of the revision log showing the whole log
97         message and the diffstat.
99 The diff view::
100         Shows either the diff of the current working tree, that is, what
101         has changed since the last commit, or the commit diff complete
102         with log message, diffstat and diff.
104 The tree view::
105         Lists directory trees associated with the current revision allowing
106         subdirectories to be descended or ascended and file blobs to be
107         viewed.
109 The blob view::
110         Displays the file content or "blob" of data associated with a file
111         name.
113 The blame view::
114         Displays the file content annotated or blamed by commits.
116 The branch view::
117         Displays the branches in the repository.
119 The status view::
120         Displays status of files in the working tree and allows changes to be
121         staged/unstaged as well as adding of untracked files.
123 The stage view::
124         Displays diff changes for staged or unstaged files being tracked or
125         file content of untracked files.
127 The pager view::
128         Is used for displaying both input from stdin and output from git
129         commands entered in the internal prompt.
131 The help view::
132         Displays a quick reference of key bindings.
134 [[commit-id]]
135 Browsing State and User-defined Commands
136 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138 The viewer keeps track of both what head and commit ID you are currently
139 viewing. The commit ID will follow the cursor line and change every time you
140 highlight a different commit. Whenever you reopen the diff view it will be
141 reloaded, if the commit ID changed. The head ID is used when opening the main
142 and log view to indicate from what revision to show history.
144 Some of the commands used or provided by tig can be configured. This goes for
145 some of the <<env-variables, environment variables>> as well as the
146 <<external-commands, external commands>>. These user-defined commands can use
147 arguments that refer to the current browsing state by using one of the
148 following variables.
150 .Browsing state variables
151 [frame="none",grid="none",cols="25<m,75<"]
152 |=============================================================================
153 |%(head)                |The currently viewed 'head' ID. Defaults to HEAD
154 |%(commit)              |The currently selected commit ID.
155 |%(blob)                |The currently selected blob ID.
156 |%(branch)              |The currently selected branch name.
157 |%(directory)           |The current directory path in the tree view;
158                          empty for the root directory.
159 |%(file)                |The currently selected file.
160 |%(ref)                 |The reference given to blame or HEAD if undefined.
161 |%(revargs)             |The revision arguments passed on the command line.
162 |%(fileargs)            |The file arguments passed on the command line.
163 |%(diffargs)            |The diff options passed on the command line.
164 |%(prompt)              |Prompt for the argument value.
165 |=============================================================================
167 Example user-defined commands:
169  - Allow to amend the last commit:
171         bind generic + !git commit --amend
173  - Copy commit ID to clipboard:
175         bind generic 9 !@sh -c "echo -n %(commit) | xclip -selection c"
177  - Add/edit notes for the current commit used during a review:
179         bind generic T !git notes edit %(commit)
181  - Enter git's interactive add for fine-grained staging of file content:
183         bind generic I !git add -i %(file)
185  - Rebase current branch on top of the selected branch:
187         bind branch 3 !git rebase -i %(branch)
189 [[title-window]]
190 Title Windows
191 ~~~~~~~~~~~~~
193 Each view has a title window which shows the name of the view, current commit
194 ID if available, and where the view is positioned:
196 -----------------------------------------------------------------------------
197 [main] c622eefaa485995320bc743431bae0d497b1d875 - commit 1 of 61 (1%)
198 -----------------------------------------------------------------------------
200 By default, the title of the current view is highlighted using bold font.  For
201 long loading views (taking over 3 seconds) the time since loading started will
202 be appended:
204 -----------------------------------------------------------------------------
205 [main] 77d9e40fbcea3238015aea403e06f61542df9a31 - commit 1 of 779 (0%) 5s
206 -----------------------------------------------------------------------------
208 [[env-variables]]
209 Environment Variables
210 ---------------------
212 Several options related to the interface with git can be configured via
213 environment options.
215 [[configuration-files]]
216 Configuration Files
217 ~~~~~~~~~~~~~~~~~~~
219 Upon startup, tig first reads the system wide configuration file
220 (`{sysconfdir}/tigrc` by default) and then proceeds to read the user's
221 configuration file (`~/.tigrc` by default). The paths to either of these files
222 can be overridden through the following environment variables:
224 TIGRC_USER::
225         Path of the user configuration file.
227 TIGRC_SYSTEM::
228         Path of the system wide configuration file.
230 [[repo-refs]]
231 Repository References
232 ~~~~~~~~~~~~~~~~~~~~~
234 Commits that are referenced by tags and branch heads will be marked by the
235 reference name surrounded by '[' and ']':
237 -----------------------------------------------------------------------------
238 2006-03-26 19:42 Petr Baudis         | [cogito-0.17.1] Cogito 0.17.1
239 -----------------------------------------------------------------------------
241 If you want to limit what branches are shown, say only show branches named
242 `master` or those which start with the `jf/` prefix, you can do it by setting
243 the following variable:
245 -----------------------------------------------------------------------------
246 $ TIG_LS_REMOTE="git ls-remote . master jf/*" tig
247 -----------------------------------------------------------------------------
249 Or set the variable permanently in your environment.
253 TIG_LS_REMOTE::
255         Set command for retrieving all repository references. The command
256         should output data in the same format as git-ls-remote(1). Defaults
257         to:
258 -----------------------------------------------------------------------------
259 git ls-remote .
260 -----------------------------------------------------------------------------
264 [[diff-options]]
265 Diff options
266 ~~~~~~~~~~~~
268 It is possible to alter how diffs are shown by the diff view. If for example
269 you prefer to have commit and author dates shown as relative dates, use:
271 -----------------------------------------------------------------------------
272 $ TIG_DIFF_OPTS="--relative-date" tig
273 -----------------------------------------------------------------------------
275 Or set the variable permanently in your environment.
277 [[keys]]
278 Default Keybindings
279 -------------------
280 Below the default key bindings are shown.
282 [[view-switching]]
283 View Switching
284 ~~~~~~~~~~~~~~
286 [frame="none",grid="none",cols="2<,8<",options="header"]
287 |=============================================================================
288 |Key    |Action
289 |m      |Switch to main view.
290 |d      |Switch to diff view.
291 |l      |Switch to log view.
292 |p      |Switch to pager view.
293 |t      |Switch to (directory) tree view.
294 |f      |Switch to (file) blob view.
295 |B      |Switch to blame view.
296 |H      |Switch to branch view.
297 |h      |Switch to help view
298 |S      |Switch to status view
299 |c      |Switch to stage view
300 |=============================================================================
302 [[view-manipulation]]
303 View Manipulation
304 ~~~~~~~~~~~~~~~~~
306 [frame="none",grid="none",cols="2<,8<",options="header"]
307 |=============================================================================
308 |Key    |Action
309 |q      |Close view, if multiple views are open it will jump back to the
310         previous view in the view stack. If it is the last open view it
311         will quit. Use 'Q' to quit all views at once.
312 |Enter  |This key is "context sensitive" depending on what view you are
313         currently in. When in log view on a commit line or in the main
314         view, split the view and show the commit diff. In the diff view
315         pressing Enter will simply scroll the view one line down.
316 |Tab    |Switch to next view.
317 |R      |Reload and refresh the current view.
318 |O      |Maximize the current view to fill the whole display.
319 |Up     |This key is "context sensitive" and will move the cursor one
320         line up. However, if you opened a diff view from the main view
321         (split- or full-screen) it will change the cursor to point to
322         the previous commit in the main view and update the diff view
323         to display it.
324 |Down   |Similar to 'Up' but will move down.
325 |,      |Move to parent. In the tree view, this means switch to the parent
326         directory. In the blame view it will load blame for the parent
327         commit. For merges the parent is queried.
328 |=============================================================================
330 [[view-actions]]
331 View Specific Actions
332 ~~~~~~~~~~~~~~~~~~~~~
334 [frame="none",grid="none",cols="2<,8<",options="header"]
335 |=============================================================================
336 |Key    |Action
337 |u      |Update status of file. In the status view, this allows you to add an
338          untracked file or stage changes to a file for next commit (similar to
339          running git-add <filename>). In the stage view, when pressing this on
340          a diff chunk line stages only that chunk for next commit, when not on
341          a diff chunk line all changes in the displayed diff are staged.
342 |M      |Resolve unmerged file by launching git-mergetool(1). Note, to work
343          correctly this might require some initial configuration of your
344          preferred merge tool. See the manpage of git-mergetool(1).
345 |!      |Checkout file with unstaged changes. This will reset the file to
346          contain the content it had at last commit.
347 |1      |Stage single diff line.
348 |@      |Move to next chunk in the stage view.
349 |]      |Increase the diff context.
350 |[      |Decrease the diff context.
351 |=============================================================================
353 [[cursor-nav]]
354 Cursor Navigation
355 ~~~~~~~~~~~~~~~~~
357 [frame="none",grid="none",cols="2<,8<",options="header"]
358 |=============================================================================
359 |Key            |Action
360 |k              |Move cursor one line up.
361 |j              |Move cursor one line down.
362 |PgUp,-,a       |Move cursor one page up.
363 |PgDown, Space  |Move cursor one page down.
364 |End            |Jump to last line.
365 |Home           |Jump to first line.
366 |=============================================================================
368 [[view-scrolling]]
369 Scrolling
370 ~~~~~~~~~
372 [frame="none",grid="none",cols="2<,8<",options="header"]
373 |=============================================================================
374 |Key    |Action
375 |Insert |Scroll view one line up.
376 |Delete |Scroll view one line down.
377 |w      |Scroll view one page up.
378 |s      |Scroll view one page down.
379 |Left   |Scroll view one column left.
380 |Right  |Scroll view one column right.
381 |\|     |Scroll view to the first column.
382 |=============================================================================
384 [[searching]]
385 Searching
386 ~~~~~~~~~
388 [frame="none",grid="none",cols="2<,8<",options="header"]
389 |=============================================================================
390 |Key    |Action
391 |/      |Search the view. Opens a prompt for entering search regexp to use.
392 |?      |Search backwards in the view. Also prompts for regexp.
393 |n      |Find next match for the current search regexp.
394 |N      |Find previous match for the current search regexp.
395 |=============================================================================
397 [[misc-keys]]
398 Misc
399 ~~~~
401 [frame="none",grid="none",cols="2<,8<",options="header"]
402 |=============================================================================
403 |Key    |Action
404 |Q      |Quit.
405 |r      |Redraw screen.
406 |z      |Stop all background loading. This can be useful if you use
407          tig in a repository with a long history without limiting
408          the revision log.
409 |v      |Show version.
410 |o      |Open option menu
411 |.      |Toggle line numbers on/off.
412 |D      |Toggle date display on/off/short/relative/local.
413 |A      |Toggle author display on/off/abbreviated/email/email username.
414 |g      |Toggle revision graph visualization on/off.
415 |~      |Toggle (line) graphics mode
416 |F      |Toggle reference display on/off (tag and branch names).
417 |W      |Toggle ignoring whitespace on/off for diffs
418 |X      |Toggle commit ID display on/off
419 |:      |Open prompt. This allows you to specify what command to run.
420 |e      |Open file in editor.
421 |=============================================================================
423 [[prompt]]
424 Prompt
425 ~~~~~~
427 [frame="none",grid="none",cols="2<,8<",options="header"]
428 |=============================================================================
429 |Key            |Action
430 |:<number>      |Jump to the specific line number, e.g. `:80`.
431 |:<sha>         |Jump to a specific commit, e.g. `:2f12bcc`.
432 |:<x>           |Execute the corresponding key binding, e.g. `:q`.
433 |:!<command>    |Execute a system command in a pager, e.g. `:!git log -p`.
434 |:<action>      |Execute a tig command, e.g. `:edit`.
435 |=============================================================================
437 [[external-commands]]
438 External Commands
439 ~~~~~~~~~~~~~~~~~
441 For more custom needs, external commands provide a way to easily execute
442 a script or program. They are bound to keys and use information from the
443 current browsing state, such as the current commit ID. Tig comes with
444 the following built-in external commands:
446 [frame="none",grid="none",cols="1<,1<,8<",options="header"]
447 |=============================================================================
448 |Keymap |Key    |Action
449 |main   |C      |git cherry-pick %(commit)
450 |status |C      |git commit
451 |generic|G      |git gc
452 |=============================================================================
454 [[refspec]]
455 Revision Specification
456 ----------------------
458 This section describes various ways to specify what revisions to display or
459 otherwise limit the view to. Tig does not itself parse the described
460 revision options so refer to the relevant git man pages for further
461 information. Relevant man pages besides git-log(1) are git-diff(1) and
462 git-rev-list(1).
464 You can tune the interaction with git by making use of the options explained
465 in this section. For example, by configuring the environment variable
466 described in the section on <<diff-options, diff options>>.
468 [[path-limiting]]
469 Limit by Path Name
470 ~~~~~~~~~~~~~~~~~~
472 If you are interested only in those revisions that made changes to a specific
473 file (or even several files) list the files like this:
475 -----------------------------------------------------------------------------
476 $ tig Makefile README
477 -----------------------------------------------------------------------------
479 To avoid ambiguity with tig's subcommands or repository references such as tag
480 names, be sure to separate file names from other git options using "`--`". So
481 if you have a file named 'status' it will clash with the 'status' subcommand,
482 and thus you will have to use:
484 -----------------------------------------------------------------------------
485 $ tig -- status
486 -----------------------------------------------------------------------------
488 [[date-number-limiting]]
489 Limit by Date or Number
490 ~~~~~~~~~~~~~~~~~~~~~~~
492 To speed up interaction with git, you can limit the amount of commits to show
493 both for the log and main view. Either limit by date using e.g.
494 `--since=1.month` or limit by the number of commits using `-n400`.
496 If you are only interested in changes that happened between two dates you can
497 use:
499 -----------------------------------------------------------------------------
500 $ tig --after="May 5th" --before="2006-05-16 15:44"
501 -----------------------------------------------------------------------------
503 NOTE: If you want to avoid having to quote dates containing spaces you can use
504 "." instead, e.g. `--after=May.5th`.
506 [[commit-range-limiting]]
507 Limiting by Commit Ranges
508 ~~~~~~~~~~~~~~~~~~~~~~~~~
510 Alternatively, commits can be limited to a specific range, such as "all
511 commits between 'tag-1.0' and 'tag-2.0'". For example:
513 -----------------------------------------------------------------------------
514 $ tig tag-1.0..tag-2.0
515 -----------------------------------------------------------------------------
517 This way of commit limiting makes it trivial to only browse the commits which
518 haven't been pushed to a remote branch. Assuming 'origin' is your upstream
519 remote branch, using:
521 -----------------------------------------------------------------------------
522 $ tig origin..HEAD
523 -----------------------------------------------------------------------------
525 will list what will be pushed to the remote branch. Optionally, the ending
526 'HEAD' can be left out since it is implied.
528 [[reachability-limiting]]
529 Limiting by Reachability
530 ~~~~~~~~~~~~~~~~~~~~~~~~
532 Git interprets the range specifier "tag-1.0..tag-2.0" as "all commits
533 reachable from 'tag-2.0' but not from 'tag-1.0'".  Where reachability refers
534 to what commits are ancestors (or part of the history) of the branch or tagged
535 revision in question.
537 If you prefer to specify which commit to preview in this way use the
538 following:
540 -----------------------------------------------------------------------------
541 $ tig tag-2.0 ^tag-1.0
542 -----------------------------------------------------------------------------
544 You can think of '^' as a negation operator. Using this alternate syntax, it
545 is possible to further prune commits by specifying multiple branch cut offs.
547 [[refspec-combi]]
548 Combining Revisions Specification
549 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
551 Revision options can to some degree be combined, which makes it possible to
552 say "show at most 20 commits from within the last month that changed files
553 under the Documentation/ directory."
555 -----------------------------------------------------------------------------
556 $ tig --since=1.month -n20 -- Documentation/
557 -----------------------------------------------------------------------------
559 [[refspec-all]]
560 Examining All Repository References
561 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
563 In some cases, it can be useful to query changes across all references in a
564 repository. An example is to ask "did any line of development in this
565 repository change a particular file within the last week". This can be
566 accomplished using:
568 -----------------------------------------------------------------------------
569 $ tig --all --since=1.week -- Makefile
570 -----------------------------------------------------------------------------
572 include::BUGS[]
574 [[copy-right]]
575 Copyright
576 ---------
578 Copyright (c) 2006-2012 Jonas Fonseca <fonseca@diku.dk>
580 This program is free software; you can redistribute it and/or modify
581 it under the terms of the GNU General Public License as published by
582 the Free Software Foundation; either version 2 of the License, or
583 (at your option) any later version.
585 [[references]]
586 See Also
587 --------
589 Manpages:
591  - manpage:tig[1]
592  - manpage:tigrc[5]
594 Online resources:
596 include::SITES[]