6

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?

5
  • 1
    The message is the comment in this case. Commented Oct 23, 2013 at 22:35
  • The 'message' ends up as the title / header for the commit. Commented Oct 23, 2013 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. Commented Oct 23, 2013 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. Commented Oct 23, 2013 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 Commented Oct 23, 2013 at 22:40

4 Answers 4

10

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there any multiline comment option?
I'm not sure there's much need for multiline comments, since they're not included in the commit message anyway, right? Multiline commit messages work as mentioned in the answer though!
3

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.

2 Comments

Can we append git notes the end of a commit message while editing?
@alper Git notes are separate from the Git commit - that's what allows them to be edited and attached later. If want some sort of comments that can be added while committing and also later to existing commits, the commit and note adding would be separate - unless you're using Git's command-line interface where you could write a git commit-and-note wrapper that would first commit and then add the note (or even launch the editor yourself, split the message, and then do both).
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. ;)

Comments

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.

1 Comment

I'm in the console version of vim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.