Git commit opens an empty text file, for what?

In all the Git tutorials I've read, they say what you can do:

git init git add . git commit 

When I do this, I get a large text file open. It seems that none of the tutorials affect this, so I don’t know what to do with the file or what it needs to be inserted.

+84
git git-commit
Sep 13 '08 at 2:48
source share
17 answers

You are about to place the commit message in this text file, then save and exit.

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

 git config --global core.editor "nano" 

You need to change nano to any command that usually opens a text editor.

+114
Feb 10 '09 at 12:21
source share

As Ben Collins mentioned, without the -m "..." argument to enter a built-in commit message (usually a bad idea, as it encourages you to be concise), this "large text file" that opens is the window into which you need to enter a commit message.

It is generally recommended that you write a summary in the first line, skip a line, and then write more detailed notes below; this helps programs that do things like email, commit messages with the appropriate subject line and a complete list of changes made in the body.

Instead of changing the shell EDITOR you can also change the editor used by adding extra lines to the ~/.gitconfig :

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

This 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 these file types, which, as I know, I never want to put into the repository.

+62
Sep 13 '08 at 3:44
source share

The text file that opens is a summary of the current commit operation. The end of git puts you in this file so that you can add a commit message at the top of the file. Once you have added your message, just save and exit this file.

This command also has a "-m msg" switch, which allows you to add a commit message on the command line.

+37
13 Sep '08 at 3:00
source share

Assuming your editor uses vi / vim by default, you can exit the commit message editor by typing:

 :x 

which will save and leave the commit message file. You will then return to the normal git section.

Additional vi commands:
http://www.lagmonster.org/docs/vi.html

+15
Apr 21 2018-11-21T00:
source share

If you are using Mac OS X and using BBEdit, you can install this as a message editor for fixing:

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

After editing is complete, save and close the file, and git will use it for comments.

+14
Sep 06 '09 at 8:54
source share

The -m for commit allows you to enter a commit message on the command line:

 git commit -m "my first commit" 
+12
Sep 13 '08 at 2:58
source share

Like everyone said that this is exactly the place where you add a commit comment, but for some it can still confuse esp if you haven't configured your editor options and you don't know what VI : then you may be in shock, because what do you think you're still in git - bash

In this case, you are actually in a text editor with some interesting ways of working with things, and this set of commands can help you so that you can go through your first commit and then set up an editor that you are familiar with, or use it as opportunities to learn how to use it.

+12
Jan 21 '09 at 20:20
source share

When you create a new commit, git launches a text editor and writes some things to it.

Using this text editor, you intend to write a commit message that will be associated with your commit.

After you finish this, save and exit the text editor. git will use what you wrote as a commit message.

A commit message has a specific structure, described as follows:

The first line of the commit message is used as the message header (or header). The preferred commit header length is less than 40 characters, as this is the number of characters that github displays on the Commits tab of this repository before trimming it, which some people find annoying.

When compiling a heading, using a capitalized, present tense verb for the first word is common practice, although not required at all.

One new line defines the title and body of the message.

The body may consist of what you like. An overview of the changes made by your commit is reasonable. Some third-party applications use information including the body of the commit message to establish various types of intercepts (I think Gerrit and Pivotal Tracker, to name two).

Here is a short and sweet example. The lead # denotes a comment.

 Gitignore index.pyc Ignore gunicorn generated binary file # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch dev # Your branch is ahead of 'origin/dev' by 10 commits. # (use "git push" to publish your local commits) # # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: .gitignore # 

Here , Mr. Torvalds alone believes he is doing a good thing.

And here Tpope does the same.

As pointed out in several other answers, changing the default editor is single-line on the command line.

According to my preference:

 git config --global core.editor "vim" 
+7
Mar 20 '13 at 17:28
source share

Try Escape, then ZZ, after you finish typing your message. As others have said, when you run this commit command, it actually launches a text editor to enter the message. In my case (OS X), it was a VI, which I found out after some digging. In this case, press Escape to enter the "command" mode (as opposed to the INSERT mode), enter ZZ. I am sure that there are other ways to solve the problem, but it was for me. Never using VI or emacs, it was not obvious to me and was not mentioned in any of the beginner guides that I used. Hope this helps.

+6
Sep 23 '09 at 6:53
source share

The git commit command will open the editor specified in the EDITOR environment EDITOR so that 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.

+3
Sep 13 '08 at 2:56
source share

Yes, make sure you have a reasonable set of editors. I'm not sure that you will use the default editor, but if, like me, it is nano (say, somewhere near the top after entering text), you just need to enter a comment and then press Ctrl-x to complete. Then press y, then enter to confirm the commit.

Also, if you want to see a simple list of files that you will commit, rather than a huge list of differences in advance, try

 git diff --name-only 
+3
Sep 13 '08 at 4:09
source share

When performing version control, you should always explain what changes you made. This is usually the first time you have a comment, such as "Initial commit."

Ultimately, however, you want to make a good comment for each commit. You need something like a form:

Added experimental feature x.

X will increase the performance of the Y function in state Z. If you need X to activate it with -x or - feature-eks switches. This function request address # 1138.

+2
Sep 13 '08 at 3:11
source share

I was confused because I kept trying to enter the file name after: w in VIM. This does not cause fixation. Instead, I continued to receive the message “Aborting commit due to empty commit message”. Do not include the file name after: w .: w saves the file in .git / COMMIT_EDITMSG by default. Then: q to exit to complete the commit. Results can be viewed using git log.

+2
Jun 07 '10 at 9:00
source share

Now that I have changed my editor to emacs, everything works fine.

But before I installed this, "git commit -a" opened gedit, but also immediately finished "Aborting commit due to empty commit message". Saving the file from gedit did not affect. Explicitly assigning the editor using "git config -global core.editor" gedit "" had the same result.

There is nothing wrong with emacs, but out of curiosity, why does this not work with gedit, and is there any way to make it work?

Thank.

+2
Jan 11 '11 at 13:25
source share

For those of you who are using OS X, I have found that this command works well:
git config --global core.editor "open -t -W"

which will force git to open the default text editor (textedit in my case), and then wait for the application to exit. Keep in mind that you need to “Save” and then “Finish” textedit before committing. There are several other teams you can play with as described on this page:

Apple Developer Library - Open Team

You can also try git config --global core.editor "open -e -W" if you want git to always open textedit no matter what the default editor is.

+2
Apr 7 '12 at 2:11
source share

Being a newbie in the terminal, “Escape and then ZZ” worked for me, I had this problem for several months, and I also could not find a way around it.

Thanks TheGeoff for your simple tip!

+1
Oct 21 '10 at 1:19
source share

Perhaps the easiest way to commit all changes is:

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

Of course, there are much more detailed ways to do it, but this should get you started.

0
Jul 03 '09 at 3:37
source share



All Articles