69

I'm new to git and I'm trying to commit my first changes on a Windows machine. However, when I type in $git commit it takes me to a different screen than any online tutorials show or than what is mentioned in Pro Git. No online searching yields an explanation of how to use this screen, either.

The screen looks like this: The git commit screen I'm having trouble with

I have tried every key on the keyboard, but nothing seems to actually do the commit. Also there are all these little help options in green at the bottom of the screen that seem to be giving commands, but when I press the buttons they show it just types them into the commit message. What are those help options and how do I use them?

Everyone else seems to be using something called "vim" which I believe I chose not to install when installing Git because I thought the Windows console was fine.

So how do I actually commit and what are those green commands at the bottom of the screen? Thanks!

JBentley
  • 6,099
  • 5
  • 37
  • 72
Guy
  • 979
  • 1
  • 11
  • 21
  • Also, I can't even figure out which button to press to escape this screen and cancel the commit. "Esc" doesn't work. – Guy Jun 19 '18 at 04:10
  • 3
    If you want to write multi line commit message then use `git commit`. That is when this screen shows up. To write a single line commit message use `git commit -m ""`. To exit out of this screen, use `ctrl+x` and type in `y` to save the commit message. – Gunner Jun 19 '18 at 04:15
  • 3
    I hope you don't mind, I edited the title of your question because really it boils down to not knowing how to complete the commit using Nano (which is the text editor in your screenshot). This isn't specifically a Windows problem. – JBentley Jun 19 '18 at 04:25
  • @JBentley Oh sure, that's fine! I'm a real noob to this and I didn't know what was going on so your title is much more accurate, thanks! – Guy Jun 19 '18 at 04:27

7 Answers7

51

That screen is just a text editor and those options at the bottom, represent commands, tipically its the ctrl key + the letter for the command.

To make the commit you should write your commit message, then press ctrl+o to write your message, and then ctrl+x to exit that screen.

To avoid that screen you could do something like git commit -m 'your commit message', the -m indicates that your commit message goes in the command.

piedra
  • 1,343
  • 14
  • 13
  • 1
    Okay, thanks for being so helpful! Silly me, I tried the `shift` key + those commands, but not the `ctrl` key. And according to JBentley this is all Nano, so it all makes sense now! – Guy Jun 19 '18 at 04:54
  • 1
    @guy you can even change the text editor that git opens if you’d like. – evolutionxbox Jun 19 '18 at 07:19
  • 12
    thanks a lot. also, after pressing ctrl+o you have to hit enter ;) – Edgar Jul 15 '19 at 09:12
25

After typing your commit message, try:

  • ctrl + o
  • enter
  • ctrl + x
Had3r
  • 249
  • 3
  • 4
7

The screen is just an editor and you can find help at the bottom of it.

To make the commit, you should write your commit message, then press ctrl+o to write out your message, and then ctrl+x to exit that screen. In case you are asked to rename the commit file press ctrl+c to cancel or press enter, then press the exit command

To avoid that screen, do git commit -m "your commit message" In case you want to append changes to the last commit, do git commit --amend --no-edit

6

The reason why this happens is because a message is expected for your commit.

git commit will bring up an editor since it expects a message.

git commit -m "message here" will not bring up the editor.

You can exit Nano and just use the regular commit message command

Press ctrl + X -> press N -> git commit -m "message here"

Or write commit message in editor using nano,

You will see something like this.

[ENTER COMMIT MESSAGE HERE]
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is up to date with 'origin/master'.
#
# Changes to be committed:
#       new file:   sample.txt
#
[OR ENTER COMMIT MESSAGE HERE]



^G Get Help ^O WriteOut ^R Read File^Y Prev Page^K Cut Text ^C Cur Pos
^X Exit     ^J Justify  ^W Where Is ^V Next Page^U UnCut Tex^T To Spell
*Nano usually displays the different commands for you at the bottom.

Press ^X or ctrl + X. This will change the nano commands at the bottom to the exit flow.

Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?
 Y Yes
 N No           ^C Cancel

Press Y ->

File Name to Write:$DITMSG
^G Get Help        ^T To Files        M-M Mac Format     M-P Prepend
^C Cancel          M-D DOS Format     M-A Append         M-B Backup File

Press enter to save the commit to local git and you should be back to your terminal and ready to push the commit.

Also you can just use vim or your preferred editor,

git config --global core.editor "vim"

But personally, I prefer nano since it is way easier than vim.

deirdreamuel
  • 609
  • 8
  • 11
1

ctrl+o and ctrl+x did not work for me. I pressed ctrl+c to halt this process and some options appeared and I could commit the changes. Maybe this may help someone!

MLLDantas
  • 51
  • 6
0

As the other answers explain, first write out the message and hit control + x

After that I was asked to 'Save modified buffer'. If you choose No, then you can exit nano and the commit will be applied.

Sofía
  • 784
  • 10
  • 24
0

You can write a simple commit message like this :

git add -A

git commit -m "commit-message"

Or change your git text editor to nano to write your commit message in nano editor :

git config --global core.editor nano
git add -A
git commit 

To save the commit and exit nano editor :

ctrl + o 
y
ctrl + x
Mehdi Faraji
  • 2,574
  • 8
  • 28
  • 76