1

When I git commit -a it brings up Vim to do a commit message.

I've looked here: Using git commit -a with vim and I'm still a bit confused.

When I save and exit it brings me back out to the console and when I do git status it says that I still have work not staged for commit.

What am I missing?

Also, when doing a commit, either through the Vim window or through git commit -a -m "message" how do I add a comment?

Community
  • 1
  • 1
JDillon522
  • 16,942
  • 15
  • 41
  • 73
  • 1
    The message is the comment in this case. – Lajos Veres Oct 23 '13 at 22:35
  • The 'message' ends up as the title / header for the commit. – JDillon522 Oct 23 '13 at 22:36
  • It is the commit message. You can add multiline messages also which look like the first line is the title, and the following lines are the description. – Lajos Veres Oct 23 '13 at 22:37
  • You may be misinterpreting what you see. In Git, a "commit message" is a single block of text. By convention, the first line of this message is shown as the "title/header" in logs. When using `commit -m`, it is only easy to add a single line, not a multiline message. – Greg Hewgill Oct 23 '13 at 22:38
  • @GregHewgill Gotcha, thats what I was wondering because I hate dealing with vim. however I need to add more info sometimes. A long title message just gets wrapped into the description when you view it on github – JDillon522 Oct 23 '13 at 22:40

4 Answers4

5

A comment in a git commit might look like the following, there a comment is led with a # sign. The first line in the commit is the title. The second line, the blank one, is a delimiter to separate the title from the comment.

This is my first commit

This is the content of my 3rd line
#COMMENT
This is the content of my 4th line, not 5th

You can always just do something like the following so that you don't have to open vim at all:

git commit -am "This is my first commit <ENTER>

This is the content of my 3rd line [...]"

where the terminal will wait for the closing quotes before 'sending' the output to git.

TankorSmash
  • 11,146
  • 5
  • 55
  • 96
1

See How do I make Git use the editor of my choice for commits? for how to make your favourite editor the default for git commit messages.
And if you leave off the -m 'my commit message'from your commit command then your editor will open, letting you type to your heart's content (although you should still follow the conventions that Ingo mentioned).

P.S.: You hate vim? Wha? Does not compute. ;)

Community
  • 1
  • 1
Edward
  • 950
  • 5
  • 15
0

I suspect that your vim process is forking and returning immediately to the console before you make changes to the file. When the file is not changed git thinks you bailed out of the commit.

Try adding the -f command line argument to prevent forking, or use the console version of vim instead of the gui version.

John Weldon
  • 37,037
  • 10
  • 91
  • 126
0

In Git (as well as many other revision control systems, like Subversion), the commit message by convention consists of a (rather short) title in the first line, optionally followed by a longer description (and here is the gotcha) separated by an empty line.

In you use filetype detection in at least Vim 7.2, the Git commit message should be detected as gitcommit filetype, and proper syntax highlighting will ensure a short title and empty second line.

If you want to add arbitrary comments after the commit, git notes provides a mechanism for that; that is mostly used for attaching issue IDs, or the results of an automated build or test run.

Ingo Karkat
  • 154,018
  • 15
  • 205
  • 275