How to commit a change in git when git commit opens Nano?
GitGit CommitNanoGit Problem Overview
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.
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!
Git Solutions
Solution 1 - Git
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.
Solution 2 - Git
After typing your commit message, try:
ctrl + o
enter
ctrl + x
Solution 3 - Git
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
Solution 4 - Git
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!
Solution 5 - Git
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.
Solution 6 - Git
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.