Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git commit -a confusion

Tags:

git

vim

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

like image 675
Slee Avatar asked Nov 12 '10 13:11

Slee


3 Answers

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)

like image 157
knittl Avatar answered Sep 28 '22 20:09

knittl


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.

like image 32
Crozin Avatar answered Sep 28 '22 20:09

Crozin


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
like image 45
asm Avatar answered Sep 28 '22 19:09

asm