Rename s:PlatformSlash() to FugitiveVimPath()
[vim-fugitive.git] / doc / fugitive.txt
blob254985d21e5b57e308ec9bc0f3ea0d53faf855ea
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.
22                                                 *fugitive-:Git*
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.
28                                                 *fugitive-:Git!*
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.
34                                                 *fugitive-:Gcd*
35 :Gcd [directory]        |:cd| relative to the repository.
37                                                 *fugitive-:Glcd*
38 :Glcd [directory]       |:lcd| relative to the repository.
40                                                 *fugitive-:Gcommit*
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
46                         an empty message.
48                                                 *fugitive-:Grevert*
49 :Grevert [args]         A wrapper around git-revert.  Similar to |:Gcommit|.
51                                                 *fugitive-:Gmerge*
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.
59                                                 *fugitive-:Gpull*
60 :Gpull [args]           Like |:Gmerge|, but for git-pull.
62                                                 *fugitive-:Grebase*
63 :Grebase [args]         Like |:Gmerge|, but for git-rebase.  Interactive
64                         rebase is experimentally supported.
66                                                 *fugitive-:Gpush*
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
70                         invocation.
72                                                 *fugitive-:Gfetch*
73 :Gfetch [args]          Like |:Gpush|, but for git-fetch.
75                                         *fugitive-:Ggrep* *fugitive-:Gcgrep*
76 :Ggrep[!] [args]        |:grep|[!] with git-grep as 'grepprg'.
78                                                 *fugitive-:Glgrep*
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 [!]
84                         is given.
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.
92                                                 *fugitive-:Gllog*
93 :Gllog [args]           Like |:Gclog|, but use the location list instead of the
94                         |quickfix| list.
96                                         *fugitive-:Gedit* *fugitive-:Ge*
97 :Gedit [object]         |:edit| a |fugitive-object|.
99                                                 *fugitive-:Gsplit*
100 :Gsplit [object]        |:split| a |fugitive-object|.
102                                                 *fugitive-:Gvsplit*
103 :Gvsplit [object]       |:vsplit| a |fugitive-object|.
105                                                 *fugitive-:Gtabedit*
106 :Gtabedit [object]      |:tabedit| a |fugitive-object|.
108                                                 *fugitive-:Gpedit*
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
116                         current window.
118                                                 *fugitive-:Gread*
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}.
126                                                 *fugitive-:Gread!*
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
143                         the index.
145                                                 *fugitive-:Gwq*
146 :Gwq [path]             Like |:Gwrite| followed by |:quit| if the write
147                         succeeded.
149 :Gwq! [path]            Like |:Gwrite|! followed by |:quit|! if the write
150                         succeeded.
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
170                         window.
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.
178                                                 *fugitive-:Gmove*
179 :Gmove {destination}    Wrapper around git-mv that renames the buffer
180                         afterward.  Add a ! to pass -f.
182                                                 *fugitive-:Grename*
183 :Grename {destination}  Like |:Gmove| but operates relative to the parent
184                         directory of the current file.
186                                                 *fugitive-:Gdelete*
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
190                         buffer.
192                                                 *fugitive-:Gremove*
193 :Gremove                Like :Gdelete, but keep the (now empty) buffer around.
195                                                 *fugitive-:Gblame*
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:
201                         g?    show this help
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
206                               tree version
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
212                         -     reblame at commit
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
219                         filename.
221                                                 *fugitive-:Gbrowse*
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
245                         than opening it.
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 ~
257                                                 *fugitive_s*
258 s                       Stage (add) the file or hunk under the cursor.
260                                                 *fugitive_u*
261 u                       Unstage (reset) the file or hunk under the cursor.
263                                                 *fugitive_-*
264 -                       Stage or unstage the file or hunk under the cursor.
266                                                 *fugitive_U*
267 U                       Unstage everything.
269                                                 *fugitive_X*
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.
278                                                 *fugitive_=*
279 =                       Toggle an inline diff of the file under the cursor.
281                                                 *fugitive_>*
282 >                       Insert an inline diff of the file under the cursor.
284                                                 *fugitive_<*
285 <                       Remove the inline diff of the file under the cursor.
287                                                 *fugitive_gI*
288 gI                      Open .git/info/exclude in a split and add the file
289                         under the cursor.  Use a count to open .gitignore.
291                                                 *fugitive_I*
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.
296                                                 *fugitive_d*
297 Diff mappings ~
298                                                 *fugitive_dp*
299 dp                      Invoke |:Git!| diff on the file under the cursor.
300                         Deprecated in favor of inline diffs.
302                                                 *fugitive_dd*
303 dd                      Perform a |:Gdiffsplit| on the file under the cursor.
305                                                 *fugitive_dv*
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.
311                                                 *fugitive_dq*
312 dq                      Close all but one diff buffer, and |:diffoff|! the
313                         last one.
315                                                 *fugitive_d?*
316 d?                      Show this help.
318                                                 *fugitive-navigation-mappings*
319 Navigation mappings ~
321                                                 *fugitive_<CR>*
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
327                         it.
329                                                 *fugitive_o*
330 o                       Open the file or |fugitive-object| under the cursor in
331                         a new split.
333                                                 *fugitive_gO*
334 gO                      Open the file or |fugitive-object| under the cursor in
335                         a new vertical split.
337                                                 *fugitive_O*
338 O                       Open the file or |fugitive-object| under the cursor in
339                         a new tab.
341                                                 *fugitive_p*
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.
346                                                 *fugitive_~*
347 ~                       Open the current file in the [count]th first ancestor.
349                                                 *fugitive_P*
350 P                       Open the current file in the [count]th parent.
352                                                 *fugitive_C*
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.
361                                                 *fugitive_[c*
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.)
366                                                 *fugitive_]c*
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".)
381                                                 *fugitive_i*
382 i                       Jump to the next file or hunk, expanding inline diffs
383                         automatically.
385                                                 *fugitive_[[*
386 [[                      Jump [count] sections backward.
388                                                 *fugitive_]]*
389 ]]                      Jump [count] sections forward.
391                                                 *fugitive_[]*
392 []                      Jump [count] section ends backward.
394                                                 *fugitive_][*
395 ][                      Jump [count] section ends forward.
397                                                 *fugitive_star*
398 *                       One the first column of a + or - diff line, search for
399                         the corresponding - or + line.  Otherwise, defer to
400                         built-in |star|.
402                                                 *fugitive_#*
403 #                       Same as "*", but search backward.
405                                                 *fugitive_gu*
406 gu                      Jump to file [count] in the "Untracked" or "Unstaged"
407                         section.
409                                                 *fugitive_gU*
410 gU                      Jump to file [count] in the "Unstaged" section.
412                                                 *fugitive_gs*
413 gs                      Jump to file [count] in the "Staged" section.
415                                                 *fugitive_gp*
416 gp                      Jump to file [count] in the "Unpushed" section.
418                                                 *fugitive_gP*
419 gP                      Jump to file [count] in the "Unpulled" section.
421                                                 *fugitive_gr*
422 gr                      Jump to file [count] in the "Rebasing" section.
424                                                 *fugitive_gi*
425 gi                      Open .git/info/exclude in a split.  Use a count to
426                         open .gitignore.
428                                                 *fugitive_c*
429 Commit mappings ~
431 cc                      Create a commit.
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
444                         cursor.
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
450                         cursor.
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 ".
460                                                 *fugitive_cr*
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 ".
468                                                 *fugitive_cm*
469 cm<Space>               Populate command line with ":Gmerge ".
471 c?                      Show this help.
473                                                 *fugitive_cb*
474                                                 *fugitive_co*
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 ".
483 cb?                     Show this help.
486                                                 *fugitive_cz*
487 Stash mappings ~
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
493                         `--include-index`.
495 czA                     Apply topmost stash, or stash@{count}.
497 cza                     Apply topmost stash, or stash@{count}, preserving the
498                         index.
500 czP                     Pop topmost stash, or stash@{count}.
502 czp                     Pop topmost stash, or stash@{count}, preserving the
503                         index.
505 cz<Space>               Populate command line with ":G stash ".
507 cz?                     Show this help.
509                                                 *fugitive_r*
510 Rebase mappings ~
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
526                         rebase.
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 ".
543 r?                      Show this help.
545                                                 *fugitive-misc-mappings*
546 Miscellaneous mappings ~
548                                                 *fugitive_gq* *fugitive_q*
549 gq                      Close the status buffer.
551                                                 *fugitive_.*
552 .                       Start a |:| command line with the file under the
553                         cursor prepopulated.
555                                                 *fugitive_g?*
556 g?                      Show help for |fugitive-mappings|.
558                                                 *fugitive-global-mappings*
559 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|).
566                                                 *fugitive_y_CTRL-G*
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.
577 Object          Meaning ~
578 HEAD            .git/HEAD
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
596 :               Same as |:Gstatus|
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: