Git commit opens blank text file, for what?
In all the Git tutorials I've read they say that you can do:
git init
git add .
git commit
When I do that I get a big text file opened up. None of the tutorials seem to address this, so I don't know what to do with the file or what to put in it if anything.
You're meant to put the commit message in this text file, then save and quit.
You can change the default text editor that git uses with this command:
git config --global core.editor "nano"
You have to change nano to whatever command would normally open your text editor.
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.
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.
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.
Assuming that your editor defaults to vi/vim, you can exit the commit message editor by typing:
:x
which will save and exit the commit message file. Then you'll go back to the normal git command section.
More vi commands:
http://www.lagmonster.org/docs/vi.html