6

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
1
  • 1
    Avoid using an editor at all, simply use the -m (or -am) option and type your message between quotes and press [Enter] and you are done. (e.g. git commit -m 'Your commit message here.' then just press [Enter]) See both good answers below for configuring the default editor if you go that route. (learn/use vim - you can lean the basics in 5 minutes and it will be on just about every Linux system you touch -- well worth the time) Commented Mar 5, 2017 at 3:22

4 Answers 4

9

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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"

3 Comments

But using ^O takes me to a second set of options that I don't understand. what does M-D mean?
All you need is to hit Enter at that moment, doesn't it close the editor? If it doesn't, then ^X to exit.
@ScottF -- you may be missing the point. You can either use the -m option (or -am) and type your message between quotes and hit [Enter] to complete the commit, or you can omit the -m and the default editor (e.g. the --global core.editor) will be opened and you type your commit message there, save and quit and the commit will be completed at that point.
0

Also helpful from GentooWiki: In nano's help texts the Ctrl is represented by a caret (^), so Ctrl + W is shown as ^W, and so on. The Alt key is represented by an M (from "Meta"), so Alt + W is shown as M-W.

Comments

0

I'm guessing OP uses WSL or is new to linux. I am using a Ubuntu kernel in VS code via the Windows Subsystem for Linux (WSL, as before). There typing git commit opens a nano editor to save the commit. At least on Windows, the command to save the commit is CTRL + S. I don't think that option appears in the editor, but it worked for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.