git commit -a confusion

42,360

Solution 1

Just leave VIM (command mode -> :wq).

-a flag works like:

git add -u
git commit ...

-m flag specifies commit message. That message is mandatory so if you don't pass that (git commit -m "My message") the default text editor will be opened (you can change it in git configuration) and you'll have to write a commit message, then save and quit the editor.

Solution 2

this is a question about VIM and not git itself (if i'm not mistaken)

VIM uses multiple modes, to exit insert mode hit ESC or ^C. to save and exit the file use ZZ, :x or :wq

just to be complete: git commit -a will first add all tracked and changed files' contents to the index and then creates a commit (after specifying the commit message inside vim – or your editor of choice)

Solution 3

To save your commit you save and exit the file as you normally would in vim.

:wq

If you change your mind and want to abort you exit without saving.

:q!

You don't have to use VIM though, you can set the editor, for example the following would change the editor git uses to textmate.

git config --global core.editor textmate

Solution 4

As others have said, Vim is being opened so you an add a message with information about the changes you're committing. It seems the default editor on your system is Vim. Git is set up so that it will include whatever message you type and save in Vim, after you close Vim with :wq, :x, or some other command.

In addition to method Andrew Myers suggests of changing the editor being called by Git, you can include a simple message on the command line with something like this:

git commit -am 'This is my message for the commit. . . '

If you do it that way Git will not bother you by opening a text editor at all.

Share:
42,360
Slee
Author by

Slee

Updated on July 13, 2022

Comments

  • Slee
    Slee almost 2 years

    I am using Git Bash and am trying to figure out what is happening when I type 'git commit -a'.

    Looks like VIM opens up to edit my commit message but how do I save and actually complete this commit? I type in the editor and hit enter but it just creates another line.

    FYI: I am using VM Fusion on my mac so some of my keys might be a little different

  • knittl
    knittl over 13 years
    git commit -a does not work like git add ., it works like git add -u
  • Slee
    Slee over 13 years
    right, I was just trying to save a step and understand how to work in vim - thanks
  • Pup
    Pup almost 12 years
    "then save and quit the editor" NOTE: Exiting the editor saves the commit message.
  • Bono
    Bono almost 12 years
    You just fixed an hour of headaches for me.. lol Thanks. the ESC did the trick ;)
  • Corvus
    Corvus over 10 years
    -1 "just leave vim" may be the most unhelpful instruction ever. You might as well tell the Minotaur to "just leave the maze"
  • Jack
    Jack about 7 years
    Can you explain what 'git add -u' does? I'm new to git and am extremely confused on what that does.