fugitive.txt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. *fugitive.txt* A Git wrapper so awesome, it should be illegal
  2. Author: Tim Pope <http://tpo.pe/>
  3. License: Same terms as Vim itself (see |license|)
  4. This plugin is only available if 'compatible' is not set.
  5. INTRODUCTION *fugitive*
  6. Whenever you edit a file from a Git repository, a set of commands is defined
  7. that serve as a gateway to Git.
  8. COMMANDS *fugitive-commands*
  9. These commands are local to the buffers in which they work (generally, buffers
  10. that are part of Git repositories).
  11. *fugitive-:Git*
  12. :Git [args] Run an arbitrary git command. Similar to :!git [args]
  13. but chdir to the repository tree first.
  14. *fugitive-:Git!*
  15. :Git! [args] Like |:Git|, but capture the output into a temp file,
  16. and edit that temp file.
  17. *fugitive-:Gcd*
  18. :Gcd [directory] |:cd| relative to the repository.
  19. *fugitive-:Glcd*
  20. :Glcd [directory] |:lcd| relative to the repository.
  21. *fugitive-:Gstatus*
  22. :Gstatus Bring up the output of git-status in the preview
  23. window. The following maps, which work on the cursor
  24. line file where sensible, are provided:
  25. g? show this help
  26. <C-N> next file
  27. <C-P> previous file
  28. <CR> |:Gedit|
  29. - |:Git| add
  30. - |:Git| reset (staged files)
  31. a Show alternative format
  32. cA |:Gcommit| --amend --reuse-message=HEAD
  33. ca |:Gcommit| --amend
  34. cc |:Gcommit|
  35. cva |:Gcommit| --amend --verbose
  36. cvc |:Gcommit| --verbose
  37. D |:Gdiff|
  38. ds |:Gsdiff|
  39. dp |:Git!| diff (p for patch; use :Gw to apply)
  40. dp |:Git| add --intent-to-add (untracked files)
  41. dv |:Gvdiff|
  42. O |:Gtabedit|
  43. o |:Gsplit|
  44. p |:Git| add --patch
  45. p |:Git| reset --patch (staged files)
  46. q close status
  47. r reload status
  48. S |:Gvsplit|
  49. U |:Git| checkout
  50. U |:Git| checkout HEAD (staged files)
  51. U |:Git| clean (untracked files)
  52. U |:Git| rm (unmerged files)
  53. *fugitive-:Gcommit*
  54. :Gcommit [args] A wrapper around git-commit. If there is nothing
  55. to commit, |:Gstatus| is called instead. Unless the
  56. arguments given would skip the invocation of an editor
  57. (e.g., -m), a split window will be used to obtain a
  58. commit message, or a new tab if -v is given. Write
  59. and close that window (:wq or |:Gwrite|) to finish the
  60. commit. Unlike when running the actual git-commit
  61. command, it is possible (but unadvisable) to alter the
  62. index with commands like git-add and git-reset while a
  63. commit message is pending.
  64. *fugitive-:Gmerge*
  65. :Gmerge [args] Calls git-merge and loads errors and conflicted files
  66. into the quickfix list. Opens a |:Gcommit| style
  67. split window for the commit message if the merge
  68. succeeds. If called during a merge conflict, the
  69. conflicted files from the current index are loaded
  70. into the quickfix list.
  71. *fugitive-:Gpull*
  72. :Gpull [args] Like |:Gmerge|, but for git-pull.
  73. *fugitive-:Gpush*
  74. :Gpush [args] Invoke git-push, load the results into the quickfix
  75. list, and invoke |:cwindow| to reveal any errors.
  76. |:Dispatch| is used if available for asynchronous
  77. invocation.
  78. *fugitive-:Gfetch*
  79. :Gfetch [args] Like |:Gpush|, but for git-fetch.
  80. *fugitive-:Ggrep*
  81. :Ggrep[!] [args] |:grep|[!] with git-grep as 'grepprg'.
  82. *fugitive-:Glgrep*
  83. :Glgrep[!] [args] |:lgrep|[!] with git-grep as 'grepprg'.
  84. *fugitive-:Glog*
  85. :Glog [args] Load all previous revisions of the current file into
  86. the quickfix list. Additional git-log arguments can
  87. be given (for example, --reverse). If "--" appears as
  88. an argument, no file specific filtering is done, and
  89. previous commits rather than previous file revisions
  90. are loaded.
  91. :{range}Glog [args] Use git-log -L to load previous revisions of the given
  92. range of the current file into the quickfix list. The
  93. cursor is positioned on the first line of the first
  94. diff hunk for each commit.
  95. *fugitive-:Gllog*
  96. :Gllog [args] Like |:Glog|, but use the location list instead of the
  97. quickfix list.
  98. *fugitive-:Gedit* *fugitive-:Ge*
  99. :Gedit [revision] |:edit| a |fugitive-revision|.
  100. *fugitive-:Gsplit*
  101. :Gsplit [revision] |:split| a |fugitive-revision|.
  102. *fugitive-:Gvsplit*
  103. :Gvsplit [revision] |:vsplit| a |fugitive-revision|.
  104. *fugitive-:Gtabedit*
  105. :Gtabedit [revision] |:tabedit| a |fugitive-revision|.
  106. *fugitive-:Gpedit*
  107. :Gpedit [revision] |:pedit| a |fugitive-revision|.
  108. :Gsplit! [args] *fugitive-:Gsplit!* *fugitive-:Gvsplit!*
  109. :Gvsplit! [args] *fugitive-:Gtabedit!* *fugitive-:Gpedit!*
  110. :Gtabedit! [args] Like |:Git!|, but open the resulting temp file in a
  111. :Gpedit! [args] split, tab, or preview window.
  112. *fugitive-:Gread*
  113. :Gread [revision] Empty the buffer and |:read| a |fugitive-revision|.
  114. When the argument is omitted, this is similar to
  115. git-checkout on a work tree file or git-add on a stage
  116. file, but without writing anything to disk.
  117. :{range}Gread [revision]
  118. |:read| in a |fugitive-revision| after {range}.
  119. *fugitive-:Gread!*
  120. :Gread! [args] Empty the buffer and |:read| the output of a Git
  121. command. For example, :Gread! show HEAD:%.
  122. :{range}Gread! [args] |:read| the output of a Git command after {range}.
  123. *fugitive-:Gw* *fugitive-:Gwrite*
  124. :Gwrite Write to the current file's path and stage the results.
  125. When run in a work tree file, it is effectively git
  126. add. Elsewhere, it is effectively git-checkout. A
  127. great deal of effort is expended to behave sensibly
  128. when the work tree or index version of the file is
  129. open in another buffer.
  130. :Gwrite {path} You can give |:Gwrite| an explicit path of where in
  131. the work tree to write. You can also give a path like
  132. :0:foo.txt or even :0 to write to just that stage in
  133. the index.
  134. *fugitive-:Gwq*
  135. :Gwq [path] Like |:Gwrite| followed by |:quit| if the write
  136. succeeded.
  137. :Gwq! [path] Like |:Gwrite|! followed by |:quit|! if the write
  138. succeeded.
  139. *fugitive-:Gdiff*
  140. :Gdiff [revision] Perform a |vimdiff| against the current file in the
  141. given revision. With no argument, the version in the
  142. index is used (which means a three-way diff during a
  143. merge conflict, making it a git-mergetool
  144. alternative). The newer of the two files is placed
  145. to the right or bottom, depending on 'diffopt' and
  146. the width of the window relative to 'textwidth'. Use
  147. |do| and |dp| and write to the index file to simulate
  148. "git add --patch". For the three-way diff, there is
  149. also d2o and d3o pulling the hunk to the middle from
  150. the left or the right window, respectively.
  151. *fugitive-:Gsdiff*
  152. :Gsdiff [revision] Like |:Gdiff|, but always split horizontally.
  153. *fugitive-:Gvdiff*
  154. :Gvdiff [revision] Like |:Gdiff|, but always split vertically.
  155. *fugitive-:Gmove*
  156. :Gmove {destination} Wrapper around git-mv that renames the buffer
  157. afterward. The destination is relative to the current
  158. directory except when started with a /, in which case
  159. it is relative to the work tree. Add a ! to pass -f.
  160. *fugitive-:Gdelete*
  161. :Gdelete Wrapper around git-rm that deletes the buffer
  162. afterward. When invoked in an index file, --cached is
  163. passed. Add a ! to pass -f and forcefully discard the
  164. buffer.
  165. *fugitive-:Gremove*
  166. :Gremove Like :Gdelete, but keep the (now empty) buffer around.
  167. *fugitive-:Gblame*
  168. :Gblame [flags] Run git-blame on the file and open the results in a
  169. scroll bound vertical split. You can give any of
  170. ltfnsewMC as flags and they will be passed along to
  171. git-blame. The following maps, which work on the
  172. cursor line commit where sensible, are provided:
  173. g? show this help
  174. A resize to end of author column
  175. C resize to end of commit column
  176. D resize to end of date/time column
  177. q close blame and return to blamed window
  178. gq q, then |:Gedit| to return to work tree version
  179. <CR> q, then open commit
  180. o open commit in horizontal split
  181. O open commit in new tab
  182. - reblame at commit
  183. ~ reblame at [count]th first grandparent
  184. P reblame at [count]th parent (like HEAD^[count])
  185. :[range]Gblame [flags] Run git-blame on the given range.
  186. *fugitive-:Gbrowse*
  187. :Gbrowse Open the current file, blob, tree, commit, or tag
  188. in your browser at the upstream hosting provider.
  189. If a range is given, it is appropriately appended to
  190. the URL as an anchor.
  191. Upstream providers can be added by installing an
  192. appropriate Vim plugin. For example, GitHub can be
  193. supported by installing rhubarb.vim, available at
  194. <https://github.com/tpope/vim-rhubarb>.
  195. The hosting provider is determined by looking at the
  196. remote for the current or specified branch and falls
  197. back to "origin". In the special case of a "."
  198. remote, a local instance of git-instaweb will be
  199. started and used.
  200. :Gbrowse {revision} Like :Gbrowse, but for a given |fugitive-revision|. A
  201. useful value here is -, which ties the URL to the
  202. latest commit rather than a volatile branch.
  203. :Gbrowse [...]@{remote} Force using the given remote rather than the remote
  204. for the current branch. The remote is used to
  205. determine which GitHub repository to link to.
  206. :{range}Gbrowse [args] Appends an anchor to the URL that emphasizes the
  207. selected lines. You almost certainly want to give a
  208. "-" argument in this case to force the URL to include
  209. an exact revision.
  210. :[range]Gbrowse! [args] Like :Gbrowse, but put the URL on the clipboard rather
  211. than opening it.
  212. MAPPINGS *fugitive-mappings*
  213. These maps are available everywhere.
  214. *fugitive-c_CTRL-R_CTRL-G*
  215. <C-R><C-G> On the command line, recall the path to the current
  216. object (that is, a representation of the object
  217. recognized by |:Gedit|).
  218. *fugitive-y_CTRL-G*
  219. ["x]y<C-G> Yank the commit SHA and path to the current object.
  220. These maps are available in Git objects.
  221. *fugitive-<CR>*
  222. <CR> Jump to the revision under the cursor.
  223. *fugitive-o*
  224. o Jump to the revision under the cursor in a new split.
  225. *fugitive-S*
  226. S Jump to the revision under the cursor in a new
  227. vertical split.
  228. *fugitive-O*
  229. O Jump to the revision under the cursor in a new tab.
  230. *fugitive--*
  231. - Go to the tree containing the current tree or blob.
  232. *fugitive-~*
  233. ~ Go to the current file in the [count]th first
  234. ancestor.
  235. *fugitive-P*
  236. P Go to the current file in the [count]th parent.
  237. *fugitive-C*
  238. C Go to the commit containing the current file.
  239. *fugitive-.*
  240. . Start a |:| command line with the current revision
  241. prepopulated at the end of the line.
  242. *fugitive-a*
  243. a Show the current tag, commit, or tree in an alternate
  244. format.
  245. SPECIFYING REVISIONS *fugitive-revision*
  246. Fugitive revisions are similar to Git revisions as defined in the "SPECIFYING
  247. REVISIONS" section in the git-rev-parse man page. For commands that accept an
  248. optional revision, the default is the file in the index for work tree files
  249. and the work tree file for everything else. Example revisions follow.
  250. Revision Meaning ~
  251. HEAD .git/HEAD
  252. master .git/refs/heads/master
  253. HEAD^{} The commit referenced by HEAD
  254. HEAD^ The parent of the commit referenced by HEAD
  255. HEAD: The tree referenced by HEAD
  256. /HEAD The file named HEAD in the work tree
  257. Makefile The file named Makefile in the work tree
  258. HEAD^:Makefile The file named Makefile in the parent of HEAD
  259. :Makefile The file named Makefile in the index (writable)
  260. - The current file in HEAD
  261. ^ The current file in the previous commit
  262. ~3 The current file 3 commits ago
  263. : .git/index (Same as |:Gstatus|)
  264. :0 The current file in the index
  265. :1 The current file's common ancestor during a conflict
  266. :2 The current file in the target branch during a conflict
  267. :3 The current file in the merged branch during a conflict
  268. :/foo The most recent commit with "foo" in the message
  269. STATUSLINE *fugitive-statusline*
  270. *fugitive#statusline()*
  271. Add %{fugitive#statusline()} to your statusline to get an indicator including
  272. the current branch and the currently edited file's commit. If you don't have
  273. a statusline, this one matches the default when 'ruler' is set:
  274. >
  275. set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P
  276. <
  277. *fugitive#head(...)*
  278. Use fugitive#head() to return the name of the current branch. If the current
  279. HEAD is detached, fugitive#head() will return the empty string, unless the
  280. optional argument is given, in which case the hash of the current commit will
  281. be truncated to the given number of characters.
  282. ABOUT *fugitive-about*
  283. Grab the latest version or report a bug on GitHub:
  284. http://github.com/tpope/vim-fugitive
  285. vim:tw=78:et:ft=help:norl: