Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit opens blank text file, for what?

Tags:

git

git-commit

People also ask

What is the purpose of a commit message?

A commit in GitHub is described as a saved change. A commit message explains what change you made to your project. It is greatly important to learn how to make a good commit message no matter if it is a personal or professional project.

What happens git commit without message?

If an empty message is specified with the option -m of git commit then the editor is started. That's unexpected and unnecessary. Instead of using the length of the message string for checking if the user specified one, directly remember if the option -m was given.

What happens when we commit a file in git?

The git commit command will save all staged changes, along with a brief description from the user, in a “commit” to the local repository. Commits are at the heart of Git usage. You can think of a commit as a snapshot of your project, where a new version of that project is created in the current repository.

What happens after typing git commit?

A git commit always requires a comment. You can give one like this git commit -m "my comment" . If you do not provide a comment here, then a text editor pops up to force you to give a comment. Sometimes, you may actually need the editor to put in the commit message.


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


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.