OSDN Git Service

Regular updates
[twpd/master.git] / tig.md
1 ---
2 title: Tig
3 category: Git
4 layout: 2017/sheet
5 updated: 2022-12-08
6 weight: -3
7 ---
8
9 ### Installing
10
11 ```bash
12 # MacOS + Homebrew
13 $ brew install tig --HEAD
14 ```
15
16 ```bash
17 # Ubuntu
18 $ sudo apt install tig
19 ```
20
21 ### Invocation
22
23 | Command             | Description                                  |
24 | ------------------- | -------------------------------------------- |
25 | `tig`               | Logs                                         |
26 | ---                 | ---                                          |
27 | `tig status`        | Status                                       |
28 | `tig blame FILE`    | Blame                                        |
29 | ---                 | ---                                          |
30 | `tig master`        | Show a branch                                |
31 | `tig test..master`  | Show difference between two branches         |
32 | `tig FILE`          | Show history of file                         |
33 | `tig v0.0.3:README` | Show contents of file in a specific revision |
34 | `tig -C /repo/path` | Run in dir `/repo/path` (like `git -C`)      |
35
36 You can substitute `git log` → `tig`.
37
38 ## Shortcut keys
39 {: .-three-column}
40
41 ### Switching views
42
43 | Shortcut | Description  |
44 | -------- | ------------ |
45 | `m`      | Main view    |
46 | `d`      | Diff         |
47 | `t`      | Tree (files) |
48 | `b`      | Blame        |
49 | `s`      | Status       |
50 | `c`      | Stage        |
51 | `y`      | Stash        |
52 | `g`      | Grep         |
53 | `h`      | Help         |
54 {: .-shortcuts}
55
56 ### All views
57
58 | Shortcut  | Description                  |
59 | ---       | ---                          |
60 | `<enter>` | Enter and open selected line |
61 | `<`       | Back to previous view state  |
62 | `<tab>`   | Move focus to next view      |
63 | `R`       | Refresh                      |
64 | `q`       | Close view                   |
65 | `Q`       | Close all (quit)             |
66 | `,`       | Parent commit                |
67 {: .-shortcuts}
68
69 ### Cursor navigation
70
71 | Shortcut  | Description                  |
72 | ---       | ---                          |
73 | `/`       | Search                       |
74 | `?`       | Search backwards             |
75 | `j`  `k`  | Up/down                      |
76 | `J`  `K`  | Next/previous                |
77 | `<space>` | Page down                    |
78 | `-`       | Page up                      |
79 | `^D`      | Half page down               |
80 | `^U`      | Half page up                 |
81 {: .-shortcuts}
82
83 ### Option toggles
84
85 | Shortcut  | Description                  |
86 | ---       | ---                          |
87 | `I`       | Toggle sort order modes      |
88 | `i`       | Change sort header           |
89 | `D`       | Toggle date display modes    |
90 | `A`       | Toggle author display modes  |
91 | `#`       | Toggle line numbers          |
92 | `~`       | Toggle line graphics         |
93 | `F`       | Toggle file names            |
94 | `W`       | Toggle ignore space          |
95 {: .-shortcuts}
96
97 ### `m` - Main view
98
99 | Shortcut  | Description                  |
100 | ---       | ---                          |
101 | `X`       | Toggle commit sha            |
102 | `C`       | Cherry pick a commit         |
103 {: .-shortcuts}
104
105 ### `s` - Status view
106
107 | Shortcut  | Description                        |
108 | ---       | ---                                |
109 | `u`       | Stage/unstage file or chunk        |
110 | `!`       | Revert file or chunk               |
111 | `C`       | Commit                             |
112 | `M`       | Merge with external tool           |
113 {: .-shortcuts}
114
115 ### `c` - Stage view
116
117 | Shortcut  | Description                        |
118 | ---       | ---                                |
119 | `u`       | Stage/unstage file or chunk        |
120 | `!`       | Revert file or chunk               |
121 | `1`       | Stage line                         |
122 | `\`       | Split current diff hunk            |
123 | `[` `]`   | Increase/decrease the diff context |
124 {: .-shortcuts}
125
126 ### `d` - Diff view
127
128 | Shortcut  | Description                        |
129 | ---       | ---                                |
130 | `[` `]`   | Increase/decrease the diff context |
131 {: .-shortcuts}
132
133 ### `y` - Stash view
134
135 | Shortcut  | Description                        |
136 | ---       | ---                                |
137 | `A`       | Apply selected stash               |
138 | `P`       | Pop selected stash                 |
139 | `!`       | Drop selected stash                |
140 {: .-shortcuts}