views:

7313

answers:

13

I am trying to learn how to use git, and in all the tutorials they say that you can do

git init
git add .
git commit

but when I do that I get a big text file opened up, and none of the tutorials seem to address this, so I dont know what to do. Any help?

+2  A: 

The git commit command will open up the editor specified in the EDITOR environment variable so you can enter a commit comment. On a Linux or BSD system, this should be vi by default, although any editor should work.

Just enter your comments and save the file.

Ben Collins
+6  A: 

The -m option to commit lets you enter a commit message on the command line:

git commit -m "my first commit"
Greg Hewgill
+22  A: 

The text file that is being opened is a summary of the current commit operation. The git commit drops you into this file so the you can add a commit message at the top of the file. Once you've added your message just save and exit from this file.

There is also a "-m msg" switch on this command that allows you to add the commit message on the command line.

Lou
A: 

When doing revision control, you should always explain what the changed you made are. Usually the first time you're have a comment such as "Initial Commit."

However in the long run you want to make a good comment for each commit. You will want something of the form:

Added experimental feature x.

X will increase the performance of feature Y in condition Z. Should you need X activate it with the -x or --feature-eks switches. This addresses feature request #1138.

Flame
+17  A: 

As mentioned by Ben Collins, without the -m "..." argument to type the commit inline (which is generally a bad idea as it encourages you to be brief), this "big text file" that is opened up is a window in which to type the commit message.

Usually it's recommended to write a summary in the first line, skip a line, and then write more detailed notes beneath; this helps programs that do things like email the commit messages with an appropriate subject line and the full list of changes made in the body.

Instead of changing the EDITOR shell variable, you can also change the editor used by adding the additional lines in your ~/.gitconfig file:

[core]
    editor = emacs
    excludesfile = /Users/will/.gitignore

That second line actually has nothing to do with your problem, but I find it really useful so I can populate my ~/.gitignore file with all those filetypes I know I'll never, ever, want to commit to a repository.

Will Robertson
A: 

Yeah, make sure you have a sensible editor set. Not sure what you're default editor will be but if, like me, it is nano (will say somewhere near the top after you type commit) you just need to type in a comment and then hit Ctrl-x to finish. Then hit y, followed by enter to affirm the commit.

Also, if you want to see a simple list of the files you'll be committing rather than a huge diff listing beforehand try

git diff --name-only
Tom Martin
+5  A: 

As all have said this is just where you add your commit comment - but for some it may still be confusing esp if you have not configured your editor settings, and you are not aware of what VI is : then you could be in for a shock, because you will think you are still in the GIT-Bash

In that case you are in fact in a text editor with some interesting ways of dealing with things and this set of commands may help you out so that you can get past your first commit and then configure an editor you are familiar with or use it as an opportunity to learn how to use it.

Stephen Bailey
I know ending up in vi always shocks me :)
Will Robertson
Things make so much more sense now. +1
Matt Ellen
+12  A: 

You can change the default text editor that git uses with this command too:

git config core.editor "nano"

You have to change nano to whatever command would normally open your text editor.

celebrus
or `git config core.editor "mcedit"`
Sorin Sbarnea
A: 

The following is probably the easiest way to commit all changes:

git commit -a -m "Type your commit message here..."

Of course there are much more detailed ways of committing, but that should get you started.

PHLAK
+2  A: 

If you’re on Mac OS X and using BBEdit, you can set this up as the editor of choice for commit messages:

git config --global core.editor "bbedit -w"

Once finished edit, save and close the file and git will use it for the comments.

Ælfric
A: 

Try Escape then ZZ, after you're done typing your message. As others have said when you run that commit command it actually runs a text editor to enter the message into. In my case (OS X) it was VI, which I figured out after some digging around. In that case, hit Escape to go into "command" mode (as opposed to INSERT mode) the enter ZZ. I'm sure there are other ways of accomplishing the task but that did it for me. Having never used VI or emacs it wasn't readily apparent to me and wasn't mentioned in any of the beginner guides I was using. Hopefully this helps.

TheGeoff
+1  A: 

I was confused because I kept trying to enter a filename after the :w in VIM. That doesn't trigger the commit. Instead I kept getting a message "Aborting commit due to empty commit message." Don't put a filename after the :w. :w saves the file to .git/COMMIT_EDITMSG by default. Then :q to exit to complete the commit. You can see the results with git log.

or you can just use :x to save and exit.
TJ Ellis
A: 

Being new to Terminal as well, "Escape and then ZZ" worked for me, I've been having this issue for months and also couldn't find a way around it.

Thanks TheGeoff for your simple advice!

Yarito