I am editing files opened split into three windows. I want to commit those into the repository. Is there any commands to do that?
Asked
Active
Viewed 1.2k times
2 Answers
60
There are a few ways to accomplish this task. I will outline the most interactive method which uses :Git
.
- Open up the status window via
:Git
- Move between files via
<c-n>
/<c-p>
- Stage/unstage files via
-
- Start committing via
cc
whilst in the status window - Create commit message and save and close window. (I prefer
:x
) - You can also use
zj
andzk
to move between sections - Using
-
on a section will stage/unstage all the files in that section
For more help with :Git
see :h :Git
or :G
when in the :Git
buffer.
Can use :Gwrite
or :Gw
and :windo
to skip the :Git
window to make this a bit faster.
:windo Gw
:Git commit
You can also skip the whole commit window by using the -m
flag. e.g. :Git commit -m "A short message"
I recommend official repo on GitHub and Vimcasts videos on Fugitive: The Fugitive Series - a retrospective
To learn more see:
:h fugitive
:h :Git
:h :Gw
:h :Git commit
:h :windo
:h :x

Joannes
- 2,569
- 3
- 17
- 39

Peter Rincker
- 43,539
- 9
- 74
- 101
-
Very helpful. The one complaint I have is that after doing `:x` to save the commit message, the status window closes too. But I often have both the status window open and the index and working copy diffed. I'm adding changes piecemeal using `diffget` (the improved version of the `--patch` workflow described in the 2nd vimcast). So what I really want is to be able to commit (and I do want to use the full window to compose my possibly multi-line message), but I don't want the status window to close after saving. Is this possible? – Jonah Apr 23 '18 at 02:33
-
2You may wan to do verbose commit `cvc` in the `:Gstatus` window or `:Gcommit --verbose`. It will open a commit message in a new tab with more your commit details – Peter Rincker Apr 23 '18 at 14:13
3
Without fugitive:
:windo !git add %
:!git commit -m "My message goes here"
The last command could be replaced with:
:!git commit --interactive

romainl
- 186,200
- 21
- 280
- 313