4

I typed in 'git -commit' and got the following on my terminal

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
#
# Initial commit
#
# Changes to be committed:
#       new file:   index.html
#       new file:   index3.html
#
# Changes not staged for commit:
#       modified:   index.html
#
# Untracked files:
#       index2.html
#

now I'm stuck on this screen and I don't know what to do to complete the commit and return back to the directory area of the terminal to continue with other tasks in the cmd. Help!

Simon Suh
  • 10,599
  • 25
  • 86
  • 110

3 Answers3

8

This is a text editor, likely vi or vim.

You can press the i key to go insert mode and type your commit message, escape when you're done, then ZZ (twice, uppercase) to exit.

Or, you can put the commit message in the command line with the -m option.

The text editor has some nice perks, like being able to easily enter new lines, etc. If vi isn't good for you, you can use git config --global core.editor <editorname> to change your editor to something more to your liking.

vcsjones
  • 138,677
  • 31
  • 291
  • 286
  • when I type in 'i', the bottom line in the terminal changes to ' -- INSERT --recording [at]u' and I can start inserting text messages. When I press 'escape', the bottom line changes to 'recording [at]u'. When I press 'zz' nothing happens, what am I doing wrong? help please! :) – Simon Suh Sep 30 '16 at 19:52
  • @SimonSuh I think you got stuck in to recording mode. Press the `q` key and "recording" should disappear, then ZZ (in capitals!) to exit. – vcsjones Sep 30 '16 at 19:54
  • Hello good sir, this helped me out but im still wondering if there is another "faster" or "better" way of accomplishing this? Do we always have to face the vim editor for every commit? I thought one could simply use " git commit -m "message" " and be done with this part. Thanks! – Eduardo Jan 01 '21 at 22:37
8

This is not related to git but with the text editor configured for use. In vim, you can press i to start entering text and save by pressing esc and :wq which would commit the message you entered.

In the above state, to quit without committing, you can do :q instead of the :wq as mentioned above.

Rishi
  • 1,163
  • 7
  • 12
-1

you need to provide a message to your commit specifying what said commit does, to that you need to do git commit -m "here you write your message"

Btw, here is a relly good article about git commit messages: http://chris.beams.io/posts/git-commit/ A good commit message is more important than you would imagine ;D

gcampes
  • 74
  • 3
  • on my cmd, if I type in 'git commit -m 'message'', and then I press enter, nothing changes on the screen. How do I exit the current screen to go back to the normal terminal area? Sorry, I'm quite new to terminals. – Simon Suh Sep 30 '16 at 19:47