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 :G [args] Same as :Git, but two characters shorter.
22 :Git {args} Run an arbitrary git command and display any output.
23 On UNIX this uses a pty and on other platforms it uses
24 a pipe, which will cause some behavior differences
25 such as the absence of progress bars. Any file the
26 command edits (for example, a commit message) will be
27 loaded into a split window. Closing that window will
28 resume running the command. A few Git subcommands
29 have different behavior; these are documented below.
32 :Git! {args} Run an arbitrary git command in the background and
33 stream the output to the preview window. Requires a
34 Vim with |setbufline()|. Press CTRL-D during an
35 interactive :Git invocation to switch to this mode
38 *:Git_--paginate* *:Git_-p*
39 :Git --paginate {args} Run an arbitrary git command, capture output to a temp
40 :Git -p {args} file, and |:split| that temp file. Pass ++curwin as
41 the first argument to |:edit| the temp file instead.
42 A temp file is always used for commands like diff and
43 log that typically uses a pager, and for any command
44 that has the pager.<cmd> Git configuration option set.
46 :{range}Git! --paginate {args}
47 :{range}Git! -p {args} Run an arbitrary git command, and insert the output
48 after {range} in the current buffer.
51 :Git With no arguments, bring up a summary window vaguely
52 akin to git-status. If a summary window is already
53 open for the current repository, it is focused
54 instead. Press g? or see |fugitive-maps| for usage.
57 :Git blame [flags] Run git-blame [flags] on the current file and open the
58 results in a scroll-bound vertical split. The
59 following maps, which work on the cursor line commit
60 where sensible, are provided:
63 A resize to end of author column
64 C resize to end of commit column
65 D resize to end of date/time column
66 gq close blame, then |:Gedit| to return to work
68 <CR> close blame, and jump to patch that added line
69 (or directly to blob for boundary commit)
70 o jump to patch or blob in horizontal split
71 O jump to patch or blob in new tab
72 p jump to patch or blob in preview window
75 The maps |fugitive_P| and |fugitive_~| are also
76 supported to reblame on a parent commit, but this is
77 inherently fragile, as the line being blamed will no
78 longer exist. The preferred alternative is to use
79 <CR> to open up the commit, select the corresponding
80 `-` line that you care about, and press <CR> twice
81 more to reblame at that line. Viewing the commit also
82 gives you additional context as to why the line
85 *g:fugitive_dynamic_colors*
86 In the GUI or a 256 color terminal, commit hashes will
87 be highlighted in different colors. To disable this:
89 let g:fugitive_dynamic_colors = 0
91 :[range]Git blame [...] If a range is given, just that part of the file will
92 :Git blame [...] {file} be blamed, and a horizontal split without
93 scrollbinding is used. You can also give an arbitrary
97 :Git[!] difftool [args] Invoke `git diff [args]` and load the changes into the
98 quickfix list. Each changed hunk gets a separate
99 quickfix entry unless you pass an option like
100 --name-only or --name-status. Jumps to the first
101 change unless [!] is given.
103 :Git difftool -y [args] Invoke `git diff [args]`, open each changed file in a
104 new tab, and invoke |:Gdiffsplit!| against the
108 :Git mergetool [args] Like |:Git_difftool|, but target merge conflicts.
110 Wrappers for Vim built-ins ~
112 These all directly map onto a built-in Vim command, and generally have names
113 that prepend "G" to the command they are wrapping. For example, :Ggrep is G
117 :Ggrep[!] [args] An approximation of |:grep|[!] with git-grep as
118 :Git[!] grep -O [args] 'grepprg'.
120 :Ggrep[!] --quiet [args]
121 :Ggrep[!] -q [args] Like |:Ggrep|, but instead of displaying output, open
125 :Glgrep[!] [args] :Ggrep but for |:lgrep|.
126 :0Git[!] grep -O [args]
129 :Gclog[!] [args] Use git-log [args] to load the commit history into the
130 |quickfix| list. Jumps to the first commit unless [!]
131 is given. This command wraps |:cfile|.
133 The quickfix list can be awkward for many use cases
134 and exhibits extremely poor performance with larger
135 data sets. Consider using |:Git| log --oneline
138 :{range}Gclog[!] [args] Use git-log -L to load previous revisions of the given
139 range of the current file into the |quickfix| list.
140 The cursor is positioned on the first line of the
141 first diff hunk for each commit. Use :0Gclog to
142 target the entire file.
145 :Gllog [args] Like |:Gclog|, but use the location list instead of the
149 :Gcd [directory] |:cd| relative to the repository.
152 :Glcd [directory] |:lcd| relative to the repository.
154 *:Gedit* *fugitive-:Ge*
155 :Gedit [object] |:edit| a |fugitive-object|.
158 :Gsplit [object] |:split| a |fugitive-object|.
161 :Gvsplit [object] |:vsplit| a |fugitive-object|.
164 :Gtabedit [object] |:tabedit| a |fugitive-object|.
167 :Gpedit [object] |:pedit| a |fugitive-object|.
170 :Gdrop [object] |:drop| a |fugitive-object|.
172 *:Gread* *fugitive-:Gr*
173 :Gread [object] Empty the buffer and |:read| a |fugitive-object|.
174 When the argument is omitted, this is similar to
175 git-checkout on a work tree file or git-add on a stage
176 file, but without writing anything to disk.
178 :{range}Gread [object] |:read| in a |fugitive-object| after {range}.
180 *:Gwrite* *fugitive-:Gw*
181 :Gwrite Write to the current file's path and stage the results.
182 When run in a work tree file, it is effectively git
183 add. Elsewhere, it is effectively git-checkout. A
184 great deal of effort is expended to behave sensibly
185 when the work tree or index version of the file is
186 open in another buffer.
188 :Gwrite {path} You can give |:Gwrite| an explicit path of where in
189 the work tree to write. You can also give a path like
190 :0:foo.txt or :0:% to write to just that stage in
194 :Gwq [path] Like |:Gwrite| followed by |:quit| if the write
197 :Gwq! [path] Like |:Gwrite|! followed by |:quit|! if the write
201 :Gdiffsplit [object] Perform a |vimdiff| against the given file, or if a
202 commit is given, the current file in that commit.
203 With no argument, the version in the index or work
204 tree is used, and the work tree version is always
205 placed to the right or bottom, depending on available
206 width. Use Vim's |do| and |dp| to stage and unstage
210 :Gdiffsplit! Diff against any and all direct ancestors, retaining
211 focus on the current window. During a merge conflict,
212 this is a three-way diff against the "ours" and
213 "theirs" ancestors. Additional d2o and d3o maps are
214 provided to obtain the hunk from the "ours" or
215 "theirs" ancestor, respectively.
217 :Gdiffsplit! {object} Like |:Gdiffsplit|, but retain focus on the current
221 :Gvdiffsplit [object] Like |:Gdiffsplit|, but always split vertically.
224 :Gdiffsplit ++novertical [object]
225 :Ghdiffsplit [object] Like |:Gdiffsplit|, but with "vertical" removed from
226 'diffopt'. The split will still be vertical if
227 combined with |:vertical|.
231 These do not directly correspond to any built-in Vim command, and have a
232 capital letter after the "G" to convey this. For example, the file move
233 operation has nothing to do with the |:move| built-in, so it is named :GMove,
237 :GMove {destination} Wrapper around git-mv that renames the buffer
238 afterward. Add a ! to pass -f.
241 :GRename {destination} Like |:GMove| but operates relative to the parent
242 directory of the current file.
245 :GDelete Wrapper around git-rm that deletes the buffer
246 afterward. When invoked in an index file, --cached is
247 passed. Add a ! to pass -f and forcefully discard the
250 *:GRemove* *:GUnlink*
251 :GRemove Like |:GDelete|, but keep the (now empty) buffer around.
255 :GBrowse Open the current file, blob, tree, commit, or tag
256 in your browser at the upstream hosting provider.
257 Upstream providers can be added by installing an
258 appropriate Vim plugin. For example, GitHub can be
259 supported by installing rhubarb.vim, available at
260 <https://github.com/tpope/vim-rhubarb>.
262 :GBrowse {object} Like :GBrowse, but for a given |fugitive-object|.
264 :{range}GBrowse [args] Appends an anchor to the URL that emphasizes the
265 selected lines. This also forces the URL to include a
266 commit rather than a branch name so it remains valid
267 if the file changes. You can give a range of "0" to
268 force this behavior without including an anchor.
270 :GBrowse [...]@{remote} Force using the given remote rather than the remote
271 for the current branch. The remote is used to
272 determine which upstream repository to link to.
274 :GBrowse {url} Open an arbitrary URL in your browser.
276 :[range]GBrowse! [args] Like :GBrowse, but put the URL on the clipboard rather
281 These maps are available in both the |fugitive-summary| buffer and Fugitive
282 object buffers, although not all maps make sense in all buffers. Mappings
283 that operate on the file or hunk under the cursor are generally available in
284 visual mode to operate on multiple files or partial hunks.
286 *fugitive-staging-maps*
287 Staging/unstaging maps ~
290 s Stage (add) the file or hunk under the cursor.
293 u Unstage (reset) the file or hunk under the cursor.
296 - Stage or unstage the file or hunk under the cursor.
299 U Unstage everything.
302 X Discard the change under the cursor. This uses
303 `checkout` or `clean` under the hood. A command is
304 echoed that shows how to undo the change. Consult
305 `:messages` to see it again. During a merge conflict,
306 use 2X to call `checkout --ours` or 3X to call
307 `checkout --theirs` .
310 = Toggle an inline diff of the file under the cursor.
313 > Insert an inline diff of the file under the cursor.
316 < Remove the inline diff of the file under the cursor.
319 gI Open .git/info/exclude in a split and add the file
320 under the cursor. Use a count to open .gitignore.
323 I Invoke |:Git| add --patch or reset --patch on the file
324 P under the cursor. On untracked files, this instead
325 calls |:Git| add --intent-to-add.
330 dp Invoke |:Git| diff on the file under the cursor.
331 Deprecated in favor of inline diffs.
334 dd Perform a |:Gdiffsplit| on the file under the cursor.
337 dv Perform a |:Gvdiffsplit| on the file under the cursor.
339 *fugitive_ds* *fugitive_dh*
340 ds Perform a |:Ghdiffsplit| on the file under the cursor.
344 dq Close all but one diff buffer, and |:diffoff|! the
350 *fugitive-navigation-maps*
354 <CR> Open the file or |fugitive-object| under the cursor.
355 In a blob, this and similar maps jump to the patch
356 from the diff where this was added, or where it was
357 removed if a count was given. If the line is still in
358 the work tree version, passing a count takes you to
362 o Open the file or |fugitive-object| under the cursor in
366 gO Open the file or |fugitive-object| under the cursor in
367 a new vertical split.
370 O Open the file or |fugitive-object| under the cursor in
374 p Open the file or |fugitive-object| under the cursor in
375 a preview window. In the status buffer, 1p is
376 required to bypass the legacy usage instructions.
379 ~ Open the current file in the [count]th first ancestor.
382 P Open the current file in the [count]th parent.
385 C Open the commit containing the current file.
387 *fugitive_CTRL-P* *fugitive_(*
388 ( Jump to the previous file, hunk, or revision.
390 *fugitive_CTRL-N* *fugitive_)*
391 ) Jump to the next file, hunk, or revision.
394 [c Jump to previous hunk, expanding inline diffs
395 automatically. (This shadows the Vim built-in |[c|
396 that provides a similar operation in |diff| mode.)
399 ]c Jump to next hunk, expanding inline diffs
400 automatically. (This shadows the Vim built-in |]c|
401 that provides a similar operation in |diff| mode.)
403 *fugitive_[/* *fugitive_[m*
404 [/ Jump to previous file, collapsing inline diffs
405 [m automatically. (Mnemonic: "/" appears in filenames,
406 "m" appears in "filenames".)
408 *fugitive_]/* *fugitive_]m*
409 ]/ Jump to next file, collapsing inline diffs
410 ]m automatically. (Mnemonic: "/" appears in filenames,
411 "m" appears in "filenames".)
414 i Jump to the next file or hunk, expanding inline diffs
418 [[ Jump [count] sections backward.
421 ]] Jump [count] sections forward.
424 [] Jump [count] section ends backward.
427 ][ Jump [count] section ends forward.
430 * On the first column of a + or - diff line, search for
431 the corresponding - or + line. Otherwise, defer to
435 # Same as "*", but search backward.
438 gu Jump to file [count] in the "Untracked" or "Unstaged"
442 gU Jump to file [count] in the "Unstaged" section.
445 gs Jump to file [count] in the "Staged" section.
448 gp Jump to file [count] in the "Unpushed" section.
451 gP Jump to file [count] in the "Unpulled" section.
454 gr Jump to file [count] in the "Rebasing" section.
457 gi Open .git/info/exclude in a split. Use a count to
465 ca Amend the last commit and edit the message.
467 ce Amend the last commit without editing the message.
469 cw Reword the last commit.
471 cvc Create a commit with -v.
473 cva Amend the last commit with -v
475 cf Create a `fixup!` commit for the commit under the
478 cF Create a `fixup!` commit for the commit under the
479 cursor and immediately rebase it.
481 cs Create a `squash!` commit for the commit under the
484 cS Create a `squash!` commit for the commit under the
485 cursor and immediately rebase it.
487 cA Create a `squash!` commit for the commit under the
488 cursor and edit the message.
490 c<Space> Populate command line with ":Git commit ".
493 crc Revert the commit under the cursor.
495 crn Revert the commit under the cursor in the index and
496 work tree, but do not actually commit the changes.
498 cr<Space> Populate command line with ":Git revert ".
501 cm<Space> Populate command line with ":Git merge ".
507 Checkout/branch maps ~
509 coo Check out the commit under the cursor.
511 cb<Space> Populate command line with ":Git branch ".
513 co<Space> Populate command line with ":Git checkout ".
521 czz Push stash. Pass a [count] of 1 to add
522 `--include-untracked` or 2 to add `--all`.
524 czw Push stash of the work-tree. Like `czz` with
527 czs Push stash of the stage. Does not accept a count.
529 czA Apply topmost stash, or stash@{count}.
531 cza Apply topmost stash, or stash@{count}, preserving the
534 czP Pop topmost stash, or stash@{count}.
536 czp Pop topmost stash, or stash@{count}, preserving the
539 cz<Space> Populate command line with ":Git stash ".
546 ri Perform an interactive rebase. Uses ancestor of
547 u commit under cursor as upstream if available.
549 rf Perform an autosquash rebase without editing the todo
550 list. Uses ancestor of commit under cursor as
551 upstream if available.
553 ru Perform an interactive rebase against @{upstream}.
555 rp Perform an interactive rebase against @{push}.
557 rr Continue the current rebase.
559 rs Skip the current commit and continue the current
562 ra Abort the current rebase.
564 re Edit the current rebase todo list.
566 rw Perform an interactive rebase with the commit under
567 the cursor set to `reword`.
569 rm Perform an interactive rebase with the commit under
570 the cursor set to `edit`.
572 rd Perform an interactive rebase with the commit under
573 the cursor set to `drop`.
575 r<Space> Populate command line with ":Git rebase ".
582 *fugitive_gq* *fugitive_q*
583 gq Close the status buffer.
586 . Start a |:| command line with the file under the
590 g? Show help for |fugitive-maps|.
592 *fugitive-global-maps*
595 *fugitive_c_CTRL-R_CTRL-G*
596 <C-R><C-G> On the command line, recall the path to the current
597 |fugitive-object| (that is, a representation of the
598 object recognized by |:Gedit|).
601 ["x]y<C-G> Yank the path to the current |fugitive-object|.
604 Global maps can be disabled with the g:fugitive_no_maps option.
606 let g:fugitive_no_maps = 1
608 SPECIFYING OBJECTS *fugitive-object* *fugitive-revision*
610 Fugitive objects are either work tree files or Git revisions as defined in the
611 "SPECIFYING REVISIONS" section in the git-rev-parse man page, with expansions
612 inspired by |cmdline-special| layered on top. For commands that accept an
613 optional object, the default is the file in the index for work tree files and
614 the work tree file for everything else. Example objects follow.
617 @ The commit referenced by @ aka HEAD
618 master The commit referenced by master
619 master^ The parent of the commit referenced by master
620 master...other The merge base of master and other
621 master: The tree referenced by master
622 ./master The file named master in the working directory
623 :(top)master The file named master in the work tree
624 Makefile The file named Makefile in the work tree
625 @^:Makefile The file named Makefile in the parent of HEAD
626 :Makefile The file named Makefile in the index (writable)
627 @~2:% The current file in the grandparent of HEAD
628 :% The current file in the index
629 :1:% The current file's common ancestor during a conflict
630 :2:# The alternate file in the target branch during a conflict
631 :3:#5 The file from buffer #5 in the merged branch during a conflict
632 ! The commit owning the current file
633 !:Makefile The file named Makefile in the commit owning the current file
634 !3^2 The second parent of the commit owning buffer #3
635 .git/config The repo config file
636 : The |fugitive-summary| buffer
637 - A temp file containing the last |:Git| invocation's output
638 <cfile> The file or commit under the cursor
640 STATUSLINE *fugitive-statusline*
642 *FugitiveStatusline()* *fugitive#statusline()*
643 Add %{FugitiveStatusline()} to your statusline to get an indicator including
644 the current branch and the currently edited file's commit. If you don't have
645 a statusline, this one matches the default when 'ruler' is set:
647 set statusline=%<%f\ %h%m%r%{FugitiveStatusline()}%=%-14.(%l,%c%V%)\ %P
649 AUTOCOMMANDS *fugitive-autocommands*
651 A handful of |User| |autocommands| are provided to allow extending and
652 overriding Fugitive behaviors. Example usage:
654 autocmd User FugitiveBlob,FugitiveStageBlob call s:BlobOverrides()
657 FugitiveTag After loading a tag object.
659 *User_FugitiveCommit*
660 FugitiveCommit After loading a commit object.
663 FugitiveTree After loading a tree (directory) object.
666 FugitiveBlob After loading a committed blob (file) object.
668 *User_FugitiveObject*
669 FugitiveObject After loading any of the 4 above buffer types.
671 *User_FugitiveStageBlob*
672 FugitiveStageBlob After loading a staged blob (file) object. These
673 buffers are 'modifiable' and oftentimes don't want the
674 same behavior as the other buffer types.
677 FugitiveIndex After loading the |fugitive-summary| buffer.
680 FugitivePager After loading a temp file created by a command like
681 :Git --paginate or :Git blame.
683 *User_FugitiveEditor*
684 FugitiveEditor After a :Git command (e.g., :Git commit) edits a file
685 (e.g., the commit message).
687 *User_FugitiveChanged*
688 FugitiveChanged After any event which can potentially change the
689 repository, for example, any invocation of |:Git|.
690 Originally intended for expiring caches, but can have
695 Officially supported functions are documented inline in plugin/fugitive.vim.
697 DEPRECATIONS *fugitive-deprecated*
699 The following commands are deprecated in favor of replacements that adhere to
700 a new naming scheme. Remember that |:Git| can be shortened to |:G|, so
701 replacements using it are just one space character longer than the legacy
704 *:Gremove* Superseded by |:GRemove|.
705 *:Gdelete* Superseded by |:GDelete|.
706 *:Gmove* Superseded by |:GMove|.
707 *:Grename* Superseded by |:GRename|.
708 *:Gbrowse* Superseded by |:GBrowse|.
709 *:Gdiff* Superseded by |:Gdiffsplit|
710 *:Gsdiff* Superseded by |:Ghdiffsplit|
711 *:Gvdiff* Superseded by |:Gvdiffsplit| or |:vert| |:Gdiffsplit|.
712 *:Gblame* Superseded by |:Git_blame|.
713 *:Gcommit* Superseded by |:Git| commit.
714 *:Gmerge* Superseded by |:Git| merge and |:Git_mergetool|.
715 *:Gpull* Superseded by |:Git| pull.
716 *:Grebase* Superseded by |:Git| rebase.
717 *:Grevert* Superseded by |:Git| revert.
718 *:Gpush* Superseded by |:Git| push.
719 *:Gfetch* Superseded by |:Git| fetch.
720 *:Glog* Superseded by |:Gclog|.
721 *:Gstatus* Superseded by |:Git| (with no arguments).
722 *:Gsplit!* Superseded by |:Git_--paginate|.
723 *:Gvsplit!* Superseded by :vert Git --paginate.
724 *:Gtabsplit!* Superseded by :tab Git --paginate.
725 *:Gpedit!* Superseded by :Git! --paginate.
728 Fugitive used to support `:autocmd User Fugitive` to run an autocommand after
729 loading any buffer belonging to a Git repository, but this has been phased
730 out. Instead, one can leverage regular autocommand events like |BufNewFile|
731 and |BufReadPost|, and check !empty(FugitiveGitDir()) to confirm Fugitive has
732 found a repository. See also |fugitive-autocommands| for other, more
735 ABOUT *fugitive-about*
737 Grab the latest version or report a bug on GitHub:
739 https://github.com/tpope/vim-fugitive
741 vim:tw=78:et:ft=help:norl: