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).
18 *fugitive-:G* *fugitive-:Gstatus*
19 :G Bring up a summary window vaguely akin to git-status.
20 :Gstatus Press g? or see |fugitive-mappings| for usage.
23 :Git {args} Run an arbitrary git command. Similar to :!git [args]
24 :G {args} but chdir to the repository tree first. For some
25 subcommands, a Fugitive command is called instead.
26 Invoking :Git push will call :Gpush for example.
29 :Git! {args} Like |:Git|, but capture the output into a temp file,
30 :Git --no-pager {args} and |:split| that temp file. Use :0Git to
31 :Git -P {args} |:edit| the temp file instead. A temp file is always
32 used for diff and log commands.
35 :Gcd [directory] |:cd| relative to the repository.
38 :Glcd [directory] |:lcd| relative to the repository.
41 :Gcommit [args] A wrapper around git-commit. Unless the arguments
42 given would skip the invocation of an editor (e.g.,
43 -m), a split window will be used to obtain a commit
44 message, or a new tab if -v is given. Write and close
45 the window (:wq) to finish the commit. To cancel, use
49 :Grevert [args] A wrapper around git-revert. Similar to |:Gcommit|.
52 :Gmerge [args] Calls git-merge and loads errors and conflicted files
53 into the |quickfix| list. Opens a |:Gcommit| style
54 split window for the commit message if the merge
55 succeeds. If called during a merge conflict, the
56 conflicted files from the current index are loaded
57 into the |quickfix| list.
60 :Gpull [args] Like |:Gmerge|, but for git-pull.
63 :Grebase [args] Like |:Gmerge|, but for git-rebase. Interactive
64 rebase is experimentally supported.
67 :Gpush [args] Invoke git-push, load the results into the |quickfix|
68 list, and invoke |:cwindow| to reveal any errors.
69 |:Dispatch| is used if available for asynchronous
73 :Gfetch [args] Like |:Gpush|, but for git-fetch.
75 *fugitive-:Ggrep* *fugitive-:Gcgrep*
76 :Ggrep[!] [args] |:grep|[!] with git-grep as 'grepprg'.
79 :Glgrep[!] [args] |:lgrep|[!] with git-grep as 'grepprg'.
81 *fugitive-:Gclog* *fugitive-:Glog*
82 :Gclog[!] [args] Use git-log [args] to load the commit history into the
83 :Glog[!] [args] |quickfix| list. Jump to the first commit unless [!]
86 :{range}Gclog[!] [args] Use git-log -L to load previous revisions of the given
87 range of the current file into the |quickfix| list.
88 The cursor is positioned on the first line of the
89 first diff hunk for each commit. Use :0Gclog to
90 target the entire file.
93 :Gllog [args] Like |:Gclog|, but use the location list instead of the
96 *fugitive-:Gedit* *fugitive-:Ge*
97 :Gedit [object] |:edit| a |fugitive-object|.
100 :Gsplit [object] |:split| a |fugitive-object|.
103 :Gvsplit [object] |:vsplit| a |fugitive-object|.
106 :Gtabedit [object] |:tabedit| a |fugitive-object|.
109 :Gpedit [object] |:pedit| a |fugitive-object|.
111 :Gsplit! [args] *fugitive-:Gsplit!* *fugitive-:Gvsplit!*
112 :Gvsplit! [args] *fugitive-:Gtabedit!* *fugitive-:Gpedit!*
113 :Gtabedit! [args] Capture the output of `git [args]` to a temp file and
114 :Gpedit! [args] open it in a split, tab, or preview window. Use
115 :0Gsplit! to suppress the split and open it in the
119 :Gread [object] Empty the buffer and |:read| a |fugitive-object|.
120 When the argument is omitted, this is similar to
121 git-checkout on a work tree file or git-add on a stage
122 file, but without writing anything to disk.
124 :{range}Gread [object] |:read| in a |fugitive-object| after {range}.
127 :Gread! [args] Empty the buffer and |:read| the output of a Git
128 command. For example, :Gread! show HEAD:%.
130 :{range}Gread! [args] |:read| the output of a Git command after {range}.
132 *fugitive-:Gw* *fugitive-:Gwrite*
133 :Gwrite Write to the current file's path and stage the results.
134 When run in a work tree file, it is effectively git
135 add. Elsewhere, it is effectively git-checkout. A
136 great deal of effort is expended to behave sensibly
137 when the work tree or index version of the file is
138 open in another buffer.
140 :Gwrite {path} You can give |:Gwrite| an explicit path of where in
141 the work tree to write. You can also give a path like
142 :0:foo.txt or :0:% to write to just that stage in
146 :Gwq [path] Like |:Gwrite| followed by |:quit| if the write
149 :Gwq! [path] Like |:Gwrite|! followed by |:quit|! if the write
152 *fugitive-:Gdiffsplit*
153 :Gdiffsplit [object] Perform a |vimdiff| against the given file, or if a
154 commit is given, the current file in that commit.
155 With no argument, the version in the index or work
156 tree is used. The newer of the two files is placed to
157 the right or bottom, depending on 'diffopt' and the
158 width of the window relative to 'textwidth'. Use
159 Vim's |do| and |dp| to stage and unstage changes.
161 *fugitive-:Gdiffsplit!*
162 :Gdiffsplit! Diff against any and all direct ancestors, retaining
163 focus on the current window. During a merge conflict,
164 this is a three-way diff against the "ours" and
165 "theirs" ancestors. Additional d2o and d3o maps are
166 provided to to obtain the hunk from the "ours" or
167 "theirs" ancestor, respectively.
169 :Gdiffsplit! {object} Like |:Gdiffsplit|, but retain focus on the current
172 *fugitive-:Gvdiffsplit*
173 :Gvdiffsplit [object] Like |:Gdiffsplit|, but always split vertically.
175 *fugitive-:Ghdiffsplit* *fugitive-:Gsdiff*
176 :Ghdiffsplit [object] Like |:Gdiffsplit|, but always split horizontally.
179 :Gmove {destination} Wrapper around git-mv that renames the buffer
180 afterward. Add a ! to pass -f.
183 :Grename {destination} Like |:Gmove| but operates relative to the parent
184 directory of the current file.
187 :Gdelete Wrapper around git-rm that deletes the buffer
188 afterward. When invoked in an index file, --cached is
189 passed. Add a ! to pass -f and forcefully discard the
193 :Gremove Like :Gdelete, but keep the (now empty) buffer around.
196 :Gblame [flags] Run git-blame [flags] on the current file and open the
197 results in a scroll-bound vertical split. The
198 following maps, which work on the cursor line commit
199 where sensible, are provided:
202 A resize to end of author column
203 C resize to end of commit column
204 D resize to end of date/time column
205 gq close blame, then |:Gedit| to return to work
207 <CR> close blame, and jump to patch that added line
208 (or directly to blob for boundary commit)
209 o jump to patch or blob in horizontal split
210 O jump to patch or blob in new tab
211 p jump to patch or blob in preview window
213 ~ reblame at [count]th first grandparent
214 P reblame at [count]th parent (like HEAD^[count])
216 :[range]Gblame [flags] If a range is given, just that part of the file will
217 :Gblame [flags] {file} be blamed, and a horizontal split without
218 scrollbinding is used. You can also give an arbitrary
222 :Gbrowse Open the current file, blob, tree, commit, or tag
223 in your browser at the upstream hosting provider.
224 If a range is given, it is appropriately appended to
225 the URL as an anchor.
227 Upstream providers can be added by installing an
228 appropriate Vim plugin. For example, GitHub can be
229 supported by installing rhubarb.vim, available at
230 <https://github.com/tpope/vim-rhubarb>.
232 :Gbrowse {object} Like :Gbrowse, but for a given |fugitive-object|.
234 :Gbrowse [...]@{remote} Force using the given remote rather than the remote
235 for the current branch. The remote is used to
236 determine which upstream repository to link to.
238 :{range}Gbrowse [args] Appends an anchor to the URL that emphasizes the
239 selected lines. This also forces the URL to include a
240 commit rather than a branch name so it remains valid
241 if the file changes. You can give a range of "0" to
242 force this behavior without including an anchor.
244 :[range]Gbrowse! [args] Like :Gbrowse, but put the URL on the clipboard rather
247 MAPPINGS *fugitive-mappings*
249 These mappings are available in both the |:Gstatus| buffer and Fugitive object
250 buffers, although not all mappings make sense in all buffers. Mappings that
251 operate on the file or hunk under the cursor are generally available in visual
252 mode to operate on multiple files or partial hunks.
254 *fugitive-staging-mappings*
255 Staging/unstaging mappings ~
258 s Stage (add) the file or hunk under the cursor.
261 u Unstage (reset) the file or hunk under the cursor.
264 - Stage or unstage the file or hunk under the cursor.
267 U Unstage everything.
270 X Discard the change under the cursor. This uses
271 `checkout` or `clean` under the hood. A command is
272 echoed that shows how to undo the change. Consult
273 `:messages` to see it again. You can use this during
274 a merge conflict do discard "our" changes (--theirs)
275 in the "Unstaged" section or discard "their" changes
276 (--ours) in the "Staged" section.
279 = Toggle an inline diff of the file under the cursor.
282 > Insert an inline diff of the file under the cursor.
285 < Remove the inline diff of the file under the cursor.
288 gI Open .git/info/exclude in a split and add the file
289 under the cursor. Use a count to open .gitignore.
292 I Invoke |:Git| add --patch or reset --patch on the file
293 P under the cursor. On untracked files, this instead
294 calls |:Git| add --intent-to-add.
299 dp Invoke |:Git!| diff on the file under the cursor.
300 Deprecated in favor of inline diffs.
303 dd Perform a |:Gdiffsplit| on the file under the cursor.
306 dv Perform a |:Gvdiffsplit| on the file under the cursor.
308 *fugitive_ds* *fugitive_dh*
309 ds Perform a |:Ghdiffsplit| on the file under the cursor.
312 dq Close all but one diff buffer, and |:diffoff|! the
318 *fugitive-navigation-mappings*
319 Navigation mappings ~
322 <CR> Open the file or |fugitive-object| under the cursor.
323 in a blob, this and similar maps jump to the patch
324 from the diff where this was added, or where it was
325 removed if a count was given. If the line is still in
326 the work tree version, passing a count takes you to
330 o Open the file or |fugitive-object| under the cursor in
334 gO Open the file or |fugitive-object| under the cursor in
335 a new vertical split.
338 O Open the file or |fugitive-object| under the cursor in
342 p Open the file or |fugitive-object| under the cursor in
343 a preview window. In the status buffer, 1p is
344 required to bypass the legacy usage instructions.
347 ~ Open the current file in the [count]th first ancestor.
350 P Open the current file in the [count]th parent.
353 C Open the commit containing the current file.
355 *fugitive_CTRL-P* *fugitive_(*
356 ( Jump to the previous file, hunk, or revision.
358 *fugitive_CTRL-N* *fugitive_)*
359 ) Jump to the next file, hunk, or revision.
362 [c Jump to previous hunk, expanding inline diffs
363 automatically. (This shadows the Vim built-in |[c|
364 that provides a similar operation in |diff| mode.)
367 ]c Jump to next hunk, expanding inline diffs
368 automatically. (This shadows the Vim built-in |]c|
369 that provides a similar operation in |diff| mode.)
371 *fugitive_[/* *fugitive_[m*
372 [/ Jump to previous file, collapsing inline diffs
373 [m automatically. (Mnemonic: "/" appears in filenames,
374 "m" appears in "filenames".)
376 *fugitive_]/* *fugitive_]m*
377 ]/ Jump to next file, collapsing inline diffs
378 ]m automatically. (Mnemonic: "/" appears in filenames,
379 "m" appears in "filenames".)
382 i Jump to the next file or hunk, expanding inline diffs
386 [[ Jump [count] sections backward.
389 ]] Jump [count] sections forward.
392 [] Jump [count] section ends backward.
395 ][ Jump [count] section ends forward.
398 * One the first column of a + or - diff line, search for
399 the corresponding - or + line. Otherwise, defer to
403 # Same as "*", but search backward.
406 gu Jump to file [count] in the "Untracked" or "Unstaged"
410 gU Jump to file [count] in the "Unstaged" section.
413 gs Jump to file [count] in the "Staged" section.
416 gp Jump to file [count] in the "Unpushed" section.
419 gP Jump to file [count] in the "Unpulled" section.
422 gr Jump to file [count] in the "Rebasing" section.
425 gi Open .git/info/exclude in a split. Use a count to
433 ca Amend the last commit and edit the message.
435 ce Amend the last commit without editing the message.
437 cw Reword the last commit.
439 cvc Create a commit with -v.
441 cva Amend the last commit with -v
443 cf Create a `fixup!` commit for the commit under the
446 cF Create a `fixup!` commit for the commit under the
447 cursor and immediately rebase it.
449 cs Create a `squash!` commit for the commit under the
452 cS Create a `squash!` commit for the commit under the
453 cursor and immediately rebase it.
455 cA Create a `squash!` commit for the commit under the
456 cursor and edit the message.
458 c<Space> Populate command line with ":Gcommit ".
461 crc Revert the commit under the cursor.
463 crn Revert the commit under the cursor in the index and
464 work tree, but do not actually commit the changes.
466 cr<Space> Populate command line with ":Grevert ".
469 cm<Space> Populate command line with ":Gmerge ".
475 Checkout/branch mappings ~
477 coo Check out the commit under the cursor.
479 cb<Space> Populate command line with ":G branch ".
481 co<Space> Populate command line with ":G checkout ".
489 czz Push stash. Pass a [count] of 1 to add
490 `--include-untracked` or 2 to add `--all`.
492 czw Push stash of worktree. Like `czz` with
495 czA Apply topmost stash, or stash@{count}.
497 cza Apply topmost stash, or stash@{count}, preserving the
500 czP Pop topmost stash, or stash@{count}.
502 czp Pop topmost stash, or stash@{count}, preserving the
505 cz<Space> Populate command line with ":G stash ".
512 ri Perform an interactive rebase. Uses ancestor of
513 u commit under cursor as upstream if available.
515 rf Perform an autosquash rebase without editing the todo
516 list. Uses ancestor of commit under cursor as
517 upstream if available.
519 ru Perform an interactive rebase against @{upstream}.
521 rp Perform an interactive rebase against @{push}.
523 rr Continue the current rebase.
525 rs Skip the current commit and continue the current
528 ra Abort the current rebase.
530 re Edit the current rebase todo list.
532 rw Perform an interactive rebase with the commit under
533 the cursor set to `reword`.
535 rm Perform an interactive rebase with the commit under
536 the cursor set to `edit`.
538 rd Perform an interactive rebase with the commit under
539 the cursor set to `drop`.
541 r<Space> Populate command line with ":Grebase ".
545 *fugitive-misc-mappings*
546 Miscellaneous mappings ~
548 *fugitive_gq* *fugitive_q*
549 gq Close the status buffer.
552 . Start a |:| command line with the file under the
556 g? Show help for |fugitive-mappings|.
558 *fugitive-global-mappings*
561 *fugitive_c_CTRL-R_CTRL-G*
562 <C-R><C-G> On the command line, recall the path to the current
563 |fugitive-object| (that is, a representation of the
564 object recognized by |:Gedit|).
567 ["x]y<C-G> Yank the path to the current |fugitive-object|.
569 SPECIFYING OBJECTS *fugitive-object* *fugitive-revision*
571 Fugitive objects are either work tree files or Git revisions as defined in the
572 "SPECIFYING REVISIONS" section in the git-rev-parse man page, with expansions
573 inspired by |cmdline-special| layered on top. For commands that accept an
574 optional object, the default is the file in the index for work tree files and
575 the work tree file for everything else. Example objects follow.
579 refs/heads/x .git/refs/heads/x (in "common dir" if present)
580 @ The commit referenced by @ aka HEAD
581 master^ The parent of the commit referenced by master
582 master: The tree referenced by master
583 ./master The file named master in the working directory
584 Makefile The file named Makefile in the work tree
585 @^:Makefile The file named Makefile in the parent of HEAD
586 :Makefile The file named Makefile in the index (writable)
587 @~2:% The current file in the grandparent of HEAD
588 :% The current file in the index
589 :1:% The current file's common ancestor during a conflict
590 :2:# The alternate file in the target branch during a conflict
591 :3:#5 The file from buffer #5 in the merged branch during a conflict
592 ! The commit owning the current file
593 !:Makefile The file named Makefile in the commit owning the current file
594 !3^2 The second parent of the commit owning buffer #3
595 .git/config The repo config file
598 STATUSLINE *fugitive-statusline*
600 *FugitiveStatusline()* *fugitive#statusline()*
601 Add %{FugitiveStatusline()} to your statusline to get an indicator including
602 the current branch and the currently edited file's commit. If you don't have
603 a statusline, this one matches the default when 'ruler' is set:
605 set statusline=%<%f\ %h%m%r%{FugitiveStatusline()}%=%-14.(%l,%c%V%)\ %P
607 *FugitiveHead(...)* *fugitive#head(...)*
608 Use FugitiveHead() to return the name of the current branch. If the current
609 HEAD is detached, FugitiveHead() will return the empty string, unless the
610 optional argument is given, in which case the hash of the current commit will
611 be truncated to the given number of characters.
613 ABOUT *fugitive-about*
615 Grab the latest version or report a bug on GitHub:
617 https://github.com/tpope/vim-fugitive
619 vim:tw=78:et:ft=help:norl: