1 *fugitive.txt* A Git wrapper so awesome, it should be illegal
3 Author: Tim Pope <http://tpo.pe/>
4 License: Same terms as Vim itself (see |license|)
6 This plugin is only available if 'compatible' is not set.
8 INTRODUCTION *fugitive*
10 Whenever you edit a file from a Git repository, a set of commands is defined
11 that serve as a gateway to Git.
13 COMMANDS *fugitive-commands*
15 These commands are local to the buffers in which they work (generally, buffers
16 that are part of Git repositories).
19 :Git {args} Run an arbitrary git command. Similar to :!git [args]
20 :G {args} but chdir to the repository tree first. For some
21 subcommands, a Fugitive command is called instead.
24 :Git! {args} Like |:Git|, but capture the output into a temp file,
25 :Git --no-pager {args} and |:split| that temp file. Use :0Git to
26 :Git -P {args} |:edit| the temp file instead. A temp file is always
27 used for diff and log commands.
30 :Git Bring up a summary window vaguely akin to git-status.
31 :G Press g? or see |fugitive-maps| for usage.
34 *:Git-commit* *:Gcommit*
35 :Git commit [args] A wrapper around git-commit. Unless the arguments
36 :Gcommit [args] given would skip the invocation of an editor (e.g.,
37 -m), a split window will be used to obtain a commit
38 message, or a new tab if -v is given. Write and close
39 the window (:wq) to finish the commit. To cancel, use
42 *:Git-revert* *:Grevert*
43 :Git revert [args] A wrapper around git-revert. Similar to |:Gcommit|.
46 *:Git-merge* *:Gmerge*
47 :Git merge [args] Calls git-merge and loads errors and conflicted files
48 :Gmerge [args] into the |quickfix| list. Opens a |:Gcommit| style
49 split window for the commit message if the merge
50 succeeds. If called during a merge conflict, the
51 conflicted files from the current index are loaded
52 into the |quickfix| list.
55 :Git pull [args] Like |:Gmerge|, but for git-pull.
58 *:Git-rebase* *:Grebase*
59 :Git rebase [args] Like |:Gmerge|, but for git-rebase. Interactive
60 :Grebase [args] rebase is experimentally supported.
63 :Git push [args] Invoke git-push, load the results into the |quickfix|
64 :Gpush [args] list, and invoke |:cwindow| to reveal any errors.
65 |:Dispatch| is used if available for asynchronous
68 *:Git-fetch* *:Gfetch*
69 :Git fetch [args] Like |:Gpush|, but for git-fetch.
72 *:Git-blame* *:Gblame*
73 :Git blame [flags] Run git-blame [flags] on the current file and open the
74 :Gblame [flags] results in a scroll-bound vertical split. The
75 following maps, which work on the cursor line commit
76 where sensible, are provided:
79 A resize to end of author column
80 C resize to end of commit column
81 D resize to end of date/time column
82 gq close blame, then |:Gedit| to return to work
84 <CR> close blame, and jump to patch that added line
85 (or directly to blob for boundary commit)
86 o jump to patch or blob in horizontal split
87 O jump to patch or blob in new tab
88 p jump to patch or blob in preview window
90 ~ reblame at [count]th first grandparent
91 P reblame at [count]th parent (like HEAD^[count])
93 :[range]Gblame [flags] If a range is given, just that part of the file will
94 :Gblame [flags] {file} be blamed, and a horizontal split without
95 :Git blame ... scrollbinding is used. You can also give an arbitrary
98 *:Ggrep* *:Gcgrep* *:Git-grep*
99 :Ggrep[!] [args] |:grep|[!] with git-grep as 'grepprg'.
103 :Glgrep[!] [args] |:lgrep|[!] with git-grep as 'grepprg'.
107 :Gclog[!] [args] Use git-log [args] to load the commit history into the
108 :Glog[!] [args] |quickfix| list. Jump to the first commit unless [!]
111 :{range}Gclog[!] [args] Use git-log -L to load previous revisions of the given
112 range of the current file into the |quickfix| list.
113 The cursor is positioned on the first line of the
114 first diff hunk for each commit. Use :0Gclog to
115 target the entire file.
118 :Gllog [args] Like |:Gclog|, but use the location list instead of the
122 :Gcd [directory] |:cd| relative to the repository.
125 :Glcd [directory] |:lcd| relative to the repository.
127 *:Gedit* *fugitive-:Ge*
128 :Gedit [object] |:edit| a |fugitive-object|.
131 :Gsplit [object] |:split| a |fugitive-object|.
134 :Gvsplit [object] |:vsplit| a |fugitive-object|.
137 :Gtabedit [object] |:tabedit| a |fugitive-object|.
140 :Gpedit [object] |:pedit| a |fugitive-object|.
142 :Gsplit! [args] *:Gsplit!* *:Gvsplit!*
143 :Gvsplit! [args] *:Gtabedit!* *:Gpedit!*
144 :Gtabedit! [args] Capture the output of `git [args]` to a temp file and
145 :Gpedit! [args] open it in a split, tab, or preview window. Use
146 :0Gsplit! to suppress the split and open it in the
149 *:Gread* *fugitive-:Gr*
150 :Gread [object] Empty the buffer and |:read| a |fugitive-object|.
151 When the argument is omitted, this is similar to
152 git-checkout on a work tree file or git-add on a stage
153 file, but without writing anything to disk.
155 :{range}Gread [object] |:read| in a |fugitive-object| after {range}.
157 *:Gread!* *fugitive-:Gr!*
158 :Gread! [args] Empty the buffer and |:read| the output of a Git
159 command. For example, :Gread! show HEAD:%.
161 :{range}Gread! [args] |:read| the output of a Git command after {range}.
163 *:Gwrite* *fugitive-:Gw*
164 :Gwrite Write to the current file's path and stage the results.
165 When run in a work tree file, it is effectively git
166 add. Elsewhere, it is effectively git-checkout. A
167 great deal of effort is expended to behave sensibly
168 when the work tree or index version of the file is
169 open in another buffer.
171 :Gwrite {path} You can give |:Gwrite| an explicit path of where in
172 the work tree to write. You can also give a path like
173 :0:foo.txt or :0:% to write to just that stage in
177 :Gwq [path] Like |:Gwrite| followed by |:quit| if the write
180 :Gwq! [path] Like |:Gwrite|! followed by |:quit|! if the write
184 :Gdiffsplit [object] Perform a |vimdiff| against the given file, or if a
185 commit is given, the current file in that commit.
186 With no argument, the version in the index or work
187 tree is used. The newer of the two files is placed to
188 the right or bottom, depending on 'diffopt' and the
189 width of the window relative to 'textwidth'. Use
190 Vim's |do| and |dp| to stage and unstage changes.
193 :Gdiffsplit! Diff against any and all direct ancestors, retaining
194 focus on the current window. During a merge conflict,
195 this is a three-way diff against the "ours" and
196 "theirs" ancestors. Additional d2o and d3o maps are
197 provided to to obtain the hunk from the "ours" or
198 "theirs" ancestor, respectively.
200 :Gdiffsplit! {object} Like |:Gdiffsplit|, but retain focus on the current
204 :Gvdiffsplit [object] Like |:Gdiffsplit|, but always split vertically.
206 *:Ghdiffsplit* *:Gsdiff*
207 :Ghdiffsplit [object] Like |:Gdiffsplit|, but always split horizontally.
210 :Gmove {destination} Wrapper around git-mv that renames the buffer
211 afterward. Add a ! to pass -f.
214 :Grename {destination} Like |:Gmove| but operates relative to the parent
215 directory of the current file.
218 :Gdelete Wrapper around git-rm that deletes the buffer
219 afterward. When invoked in an index file, --cached is
220 passed. Add a ! to pass -f and forcefully discard the
224 :Gremove Like :Gdelete, but keep the (now empty) buffer around.
227 :Gbrowse Open the current file, blob, tree, commit, or tag
228 in your browser at the upstream hosting provider.
229 If a range is given, it is appropriately appended to
230 the URL as an anchor.
232 Upstream providers can be added by installing an
233 appropriate Vim plugin. For example, GitHub can be
234 supported by installing rhubarb.vim, available at
235 <https://github.com/tpope/vim-rhubarb>.
237 :Gbrowse {object} Like :Gbrowse, but for a given |fugitive-object|.
239 :Gbrowse [...]@{remote} Force using the given remote rather than the remote
240 for the current branch. The remote is used to
241 determine which upstream repository to link to.
243 :{range}Gbrowse [args] Appends an anchor to the URL that emphasizes the
244 selected lines. This also forces the URL to include a
245 commit rather than a branch name so it remains valid
246 if the file changes. You can give a range of "0" to
247 force this behavior without including an anchor.
249 :[range]Gbrowse! [args] Like :Gbrowse, but put the URL on the clipboard rather
254 These maps are available in both the |:Gstatus| buffer and Fugitive object
255 buffers, although not all maps make sense in all buffers. Mappings that
256 operate on the file or hunk under the cursor are generally available in visual
257 mode to operate on multiple files or partial hunks.
259 *fugitive-staging-maps*
260 Staging/unstaging maps ~
263 s Stage (add) the file or hunk under the cursor.
266 u Unstage (reset) the file or hunk under the cursor.
269 - Stage or unstage the file or hunk under the cursor.
272 U Unstage everything.
275 X Discard the change under the cursor. This uses
276 `checkout` or `clean` under the hood. A command is
277 echoed that shows how to undo the change. Consult
278 `:messages` to see it again. You can use this during
279 a merge conflict do discard "our" changes (--theirs)
280 in the "Unstaged" section or discard "their" changes
281 (--ours) in the "Staged" section.
284 = Toggle an inline diff of the file under the cursor.
287 > Insert an inline diff of the file under the cursor.
290 < Remove the inline diff of the file under the cursor.
293 gI Open .git/info/exclude in a split and add the file
294 under the cursor. Use a count to open .gitignore.
297 I Invoke |:Git| add --patch or reset --patch on the file
298 P under the cursor. On untracked files, this instead
299 calls |:Git| add --intent-to-add.
304 dp Invoke |:Git!| diff on the file under the cursor.
305 Deprecated in favor of inline diffs.
308 dd Perform a |:Gdiffsplit| on the file under the cursor.
311 dv Perform a |:Gvdiffsplit| on the file under the cursor.
313 *fugitive_ds* *fugitive_dh*
314 ds Perform a |:Ghdiffsplit| on the file under the cursor.
317 dq Close all but one diff buffer, and |:diffoff|! the
323 *fugitive-navigation-maps*
327 <CR> Open the file or |fugitive-object| under the cursor.
328 in a blob, this and similar maps jump to the patch
329 from the diff where this was added, or where it was
330 removed if a count was given. If the line is still in
331 the work tree version, passing a count takes you to
335 o Open the file or |fugitive-object| under the cursor in
339 gO Open the file or |fugitive-object| under the cursor in
340 a new vertical split.
343 O Open the file or |fugitive-object| under the cursor in
347 p Open the file or |fugitive-object| under the cursor in
348 a preview window. In the status buffer, 1p is
349 required to bypass the legacy usage instructions.
352 ~ Open the current file in the [count]th first ancestor.
355 P Open the current file in the [count]th parent.
358 C Open the commit containing the current file.
360 *fugitive_CTRL-P* *fugitive_(*
361 ( Jump to the previous file, hunk, or revision.
363 *fugitive_CTRL-N* *fugitive_)*
364 ) Jump to the next file, hunk, or revision.
367 [c Jump to previous hunk, expanding inline diffs
368 automatically. (This shadows the Vim built-in |[c|
369 that provides a similar operation in |diff| mode.)
372 ]c Jump to next hunk, expanding inline diffs
373 automatically. (This shadows the Vim built-in |]c|
374 that provides a similar operation in |diff| mode.)
376 *fugitive_[/* *fugitive_[m*
377 [/ Jump to previous file, collapsing inline diffs
378 [m automatically. (Mnemonic: "/" appears in filenames,
379 "m" appears in "filenames".)
381 *fugitive_]/* *fugitive_]m*
382 ]/ Jump to next file, collapsing inline diffs
383 ]m automatically. (Mnemonic: "/" appears in filenames,
384 "m" appears in "filenames".)
387 i Jump to the next file or hunk, expanding inline diffs
391 [[ Jump [count] sections backward.
394 ]] Jump [count] sections forward.
397 [] Jump [count] section ends backward.
400 ][ Jump [count] section ends forward.
403 * One the first column of a + or - diff line, search for
404 the corresponding - or + line. Otherwise, defer to
408 # Same as "*", but search backward.
411 gu Jump to file [count] in the "Untracked" or "Unstaged"
415 gU Jump to file [count] in the "Unstaged" section.
418 gs Jump to file [count] in the "Staged" section.
421 gp Jump to file [count] in the "Unpushed" section.
424 gP Jump to file [count] in the "Unpulled" section.
427 gr Jump to file [count] in the "Rebasing" section.
430 gi Open .git/info/exclude in a split. Use a count to
438 ca Amend the last commit and edit the message.
440 ce Amend the last commit without editing the message.
442 cw Reword the last commit.
444 cvc Create a commit with -v.
446 cva Amend the last commit with -v
448 cf Create a `fixup!` commit for the commit under the
451 cF Create a `fixup!` commit for the commit under the
452 cursor and immediately rebase it.
454 cs Create a `squash!` commit for the commit under the
457 cS Create a `squash!` commit for the commit under the
458 cursor and immediately rebase it.
460 cA Create a `squash!` commit for the commit under the
461 cursor and edit the message.
463 c<Space> Populate command line with ":Git commit ".
466 crc Revert the commit under the cursor.
468 crn Revert the commit under the cursor in the index and
469 work tree, but do not actually commit the changes.
471 cr<Space> Populate command line with ":Git revert ".
474 cm<Space> Populate command line with ":Git merge ".
480 Checkout/branch maps ~
482 coo Check out the commit under the cursor.
484 cb<Space> Populate command line with ":Git branch ".
486 co<Space> Populate command line with ":Git checkout ".
494 czz Push stash. Pass a [count] of 1 to add
495 `--include-untracked` or 2 to add `--all`.
497 czw Push stash of worktree. Like `czz` with
500 czA Apply topmost stash, or stash@{count}.
502 cza Apply topmost stash, or stash@{count}, preserving the
505 czP Pop topmost stash, or stash@{count}.
507 czp Pop topmost stash, or stash@{count}, preserving the
510 cz<Space> Populate command line with ":Git stash ".
517 ri Perform an interactive rebase. Uses ancestor of
518 u commit under cursor as upstream if available.
520 rf Perform an autosquash rebase without editing the todo
521 list. Uses ancestor of commit under cursor as
522 upstream if available.
524 ru Perform an interactive rebase against @{upstream}.
526 rp Perform an interactive rebase against @{push}.
528 rr Continue the current rebase.
530 rs Skip the current commit and continue the current
533 ra Abort the current rebase.
535 re Edit the current rebase todo list.
537 rw Perform an interactive rebase with the commit under
538 the cursor set to `reword`.
540 rm Perform an interactive rebase with the commit under
541 the cursor set to `edit`.
543 rd Perform an interactive rebase with the commit under
544 the cursor set to `drop`.
546 r<Space> Populate command line with ":Git rebase ".
553 *fugitive_gq* *fugitive_q*
554 gq Close the status buffer.
557 . Start a |:| command line with the file under the
561 g? Show help for |fugitive-maps|.
563 *fugitive-global-maps*
566 *fugitive_c_CTRL-R_CTRL-G*
567 <C-R><C-G> On the command line, recall the path to the current
568 |fugitive-object| (that is, a representation of the
569 object recognized by |:Gedit|).
572 ["x]y<C-G> Yank the path to the current |fugitive-object|.
575 Global maps can be disabled with the g:fugitive_no_maps option.
577 let g:fugitive_no_maps = 1
579 SPECIFYING OBJECTS *fugitive-object* *fugitive-revision*
581 Fugitive objects are either work tree files or Git revisions as defined in the
582 "SPECIFYING REVISIONS" section in the git-rev-parse man page, with expansions
583 inspired by |cmdline-special| layered on top. For commands that accept an
584 optional object, the default is the file in the index for work tree files and
585 the work tree file for everything else. Example objects follow.
588 @ The commit referenced by @ aka HEAD
589 master The commit referenced by master
590 master^ The parent of the commit referenced by master
591 master...other The merge base of master and other
592 master: The tree referenced by master
593 ./master The file named master in the working directory
594 :(top)master The file named master in the work tree
595 Makefile The file named Makefile in the work tree
596 @^:Makefile The file named Makefile in the parent of HEAD
597 :Makefile The file named Makefile in the index (writable)
598 @~2:% The current file in the grandparent of HEAD
599 :% The current file in the index
600 :1:% The current file's common ancestor during a conflict
601 :2:# The alternate file in the target branch during a conflict
602 :3:#5 The file from buffer #5 in the merged branch during a conflict
603 ! The commit owning the current file
604 !:Makefile The file named Makefile in the commit owning the current file
605 !3^2 The second parent of the commit owning buffer #3
606 .git/config The repo config file
609 STATUSLINE *fugitive-statusline*
611 *FugitiveStatusline()* *fugitive#statusline()*
612 Add %{FugitiveStatusline()} to your statusline to get an indicator including
613 the current branch and the currently edited file's commit. If you don't have
614 a statusline, this one matches the default when 'ruler' is set:
616 set statusline=%<%f\ %h%m%r%{FugitiveStatusline()}%=%-14.(%l,%c%V%)\ %P
618 *FugitiveHead(...)* *fugitive#head(...)*
619 Use FugitiveHead() to return the name of the current branch. If the current
620 HEAD is detached, FugitiveHead() will return the empty string, unless the
621 optional argument is given, in which case the hash of the current commit will
622 be truncated to the given number of characters.
624 ABOUT *fugitive-about*
626 Grab the latest version or report a bug on GitHub:
628 https://github.com/tpope/vim-fugitive
630 vim:tw=78:et:ft=help:norl: