Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit message on linux terminal

I am trying to learn how to write a git commit message on a linux terminal.

I am presented with the following options after I write my commit message.

Which is the first one I am supposed to choose?

> ^G Get Help  ^O Write Out ^W Where Is  ^K Cut Text  ^J Justify   ^C Cur Pos
^X Exit      ^R Read File ^\ Replace   ^U Uncut Text^T To Spell  ^_ Go To Line

If I hit "write out" I get another list of options that I don't understand.

File Name to Write:$T_EDITMSG                                                   
^G Get Help     M-D DOS Format  M-A Append      M-B Backup File
^C Cancel       M-M Mac Format  M-P Prepend     ^T To Files
like image 602
Scorb Avatar asked Mar 05 '17 01:03

Scorb


People also ask

How do I write a commit message in git terminal?

To create a Git commit message with a large description, you have to execute the “git commit” command without any options. On Linux or in the Git bash, it will open an editor for you to write your Git commit message.

What is git commit in Linux?

The "commit" command is used to save your changes to the local repository. Note that you have to explicitly tell Git which changes you want to include in a commit before running the "git commit" command. This means that a file won't be automatically included in the next commit just because it was changed.


2 Answers

It's because git pick up nano as its default terminal editor, if you are not familiar with nano, you can config git to use another one.

The easiest way to write a git commit message in terminal is to use the -m option:

> git commit -m "your commit message"

But if you don't specify the -m option, git will bring you to an editor depends on the following rules

  • Git config option core.editor, local config goes first, then the global.

    • Local: git config core.editor vim, config resides in file $YOUR_REPO/.git/config
    • Global: git config --global core.editor vim, config resides in file $HOME/.gitconfig

    Please refer to Git Configuration for details.

  • Environment variables $EDITOR or $VISUAL

    • export EDITOR=`which vim`
    • export VSUAL=`which emacs`

    This is also the settings used by other tools when it needs an editor.

like image 101
shizhz Avatar answered Oct 06 '22 01:10

shizhz


When you just type git commit it will open your default text editor, nano in your case. You should type your message and hit enter after ^O.

To commit without opening a text editor:

git commit -m 'Your commit message here'

If you want to change your default editor to something else, say vim, you can do it as follows:

git config --global core.editor "vim"
like image 29
hurturk Avatar answered Oct 06 '22 00:10

hurturk