Hello! I want to talk about the console utility, which significantly increased my productivity with Git, and I hope it will speed up yours as well. It is called tig and was written by Canadian programmer Jonas Fonseca (Jonas Fonseca) back in 2006, but to this day it is being actively developed and maintained in excellent condition. I want to show its functionality (attention, there are relatively heavy gif-ki inside) and share the most convenient ways to use.
Despite the abundance of visual GUI to work with git, many developers still prefer to work in the console. There are many tools in git to increase performance — aliases, autocompletion, automatic error correction, etc., but still many ordinary actions, such as navigating through the history of commits, analyzing diffs, viewing git blame and so on, take a decent amount of time. and not always comfortable.
Installation is described in detail in the documentation on the main page of the project.
If you work on MacOS, then tig
is available via Homebrew:
brew install tig
On Linux, it is also available for all major repositories:
apt-get install tig yum install tig
For the remaining options, the standard scheme is to download the source code (from releases or via git clone
and perform make && make install
. This is described in detail in the link above.
Here is a short demo of what the interface looks like when you run the tig
command from the repository directory:
In general, as it should be, it expects from the graphical (albeit textual) interface, but using the program is quite intuitive, but first you need to learn a few basic keyboard shortcuts on which all the work with the program is built.
The main key is h
: show help window :)
As you can see, there are several modes (views) - main mode, diff view mode, log mode, file tree view mode, blame mode, current status view, etc.
It is quite simple to switch between all these modes, it is usually enough to select the necessary entry in the log or file with the arrows (or j
/ k
) and press Enter
, or, for example, in the case of blame
, the corresponding key ( b
).
Modes are displayed either in full screen or in dual-split mode. The latter is either horizontal or vertical - the program chooses it based on the aspect ratio of the terminal, and can update on the fly. To close the current mode (and return to the previous one) - just press q
(quit). To, on the contrary, maximize the window with the current mode to full screen - O
Switch between modes in dual-split mode - Tab
.
In the diff
view, it is very convenient to increase the number of lines above and below the modified line with [
and ]
(reduce and increase, respectively):
Also, the program has a file search function ( g
- grep
), search in a window ( /
), open a file in an external editor ( e
) and, in general, the interface will be especially comfortable for those familiar with vim
. For example, using :
you can enter various commands, go to the desired line, etc.
For some commands, tig
can safely work as a drop-in git
replacement.
tig status tig log tig show tig blame file tig grep pattern tig refs tig stash tig status
Also, in pager mode:
git show | tig
tig
quite flexible in terms of configuration - it has a configuration file (the path to which can also be configured via TIGRC_USER) - ~/.tigrc
and readline support.
You can create your own teams. For example, the following command copies the commit ID to the clipboard on MacOS X:
bind generic 5 !@sh -c "echo %(commit) | pbcopy"
The project has excellent documentation , more about expanding the functionality can be found in it.
tig
is one of those utilities that sped up my daily git productivity very significantly. Without switching between windows, from the terminal you get a very convenient and intuitive interface for quick navigation through the history and changes of your git repository.
The program is written in C and works monstrously fast, which is always nice, especially on large repositories.
Source: https://habr.com/ru/post/337644/
All Articles