I just executed a command $ git commit and it opens a new editor. But I'm trying to close that new commit editor. How to do this? I'm using Git for Windows.
15 Answers
Save the file in the editor. If it's Emacs: CTRLX CTRLS to save then CTRLX CTRLC to quit or if it's vi: :wq
Press esc first to get out from editing. (in windows/vi)
6 Comments
Ctrl-X Ctrl-C.C-x #Ctrlx-x command is enough to abort commit.Had troubles as well. On Linux I used Ctrl+X (and Y to confirm) and then I was back on the shell ready to pull/push.
On Windows GIT Bash Ctrl+X would do nothing and found out it works quite like vi/vim. Press i to enter inline insert mode. Type the description at the very top, press esc to exit insert mode, then type :x! (now the cursor is at the bottom) and hit enter to save and exit.
If typing :q! instead, will exit the editor without saving (and commit will be aborted)
5 Comments
nano (?) as your editor on Linux, and had not configured an editor on Windows, which caused git to choose its default, which is viAfter writing commit message, just press Esc Button and then write :wq or :wq! and then Enter to close the Unix file.
Better yet, configure the editor to something you are comfortable with (gedit as an example):
git config --global core.editor "gedit" You can read the current configuration like this:
git config core.editor You can also add the commit message from the command line.
git commit -m "blablabla" and the editor will not be opened in the first place.
After git commit command, you entered to the editor, so first hit i then start typing. After committing your message hit Ctrl+c then :wq.
2 Comments
vi or a derivative.In Mac, Press shift+Z shift+Z (capital Z twice).
3 Comments
vi, this will abort without saving the file.:help ZZ: Write current file, if modified, and close the current window (same as ":x"). If there are several windows for the current file, only the current window is closed.Alternatives to Nano (might make your life easier):
On Windows, use notepad. In command prompt type:
git config core.editor notepad
On Ubuntu / Linux, use text editor (gedit). In terminal window type:
git config core.editor gedit
1 Comment
You Just clicking the key.
first press ESC + enter and then press :x + enter
1 Comment
vi answer.I had this problem I received a ">" like prompt and I couldn't commit. I replace the " in the comment with ' and it works.
I hope this help someone!
1 Comment
I encountered the similar issue just in case this helps you.
When you hit the command git commit --amend. It opens a default editor. Now, the question was how to close this. I have just resolved this so here it is if it helps:
press Ctrl + X
Press Y to select Yes
Press Ctrl + M + A (This command saves the commit message you are editing and brings you out of editor)
Try git log command to verify your changes
1 Comment
nano editor.Not sure the key combination that gets you there to the > prompt but it is not a bash prompt that I know. I usually get it by accident. Ctrl+C (or D) gets me back to the $ prompt.
1 Comment
Note that if you're using Sublime as your commit editor, you need the -n -w flags, otherwise git keeps thinking your commit message is empty and aborting.
Comments
What exactly works depends on which editor you are in. Many of the answers here explain how to exit vi or vim (Esc followed by :wq at the prompt to save the file and exit), with some other editors thrown in; but none of them really discuss how you would know.
Git out of the box examines your VISUAL environment variable. If this is unset, it will default to vi on Unix-like platforms.
export VISUAL=nano to select nano instead. (It's not an editor I particularly like or recommend, even though it was designed specifically to be easy for beginners to understand and learn.) Obviously, if you prefer emacsclient or sublime or code, put that after the equals sign instead. No spaces on either side of the equals sign! Put this in your shell's startup file (.bash_profile or .zprofile or .profile or etc, depending on which shell you are using) to make this setting the default in new terminal instances.
Another common scenario is if you started typing in a multi-line string at the shell prompt.
bash$ git commit -m "here is my commit message > oops, I forgot the final quote > how do I fix this? > haaaaaaalp At this point, you can press ctrl-C to give up and start over. The > prompt is the shell's secondary prompt (it can be configured by changing the value of PS2, but most people don't) which is displayed when you are in the middle of a quoted string. If you want to commit with the message you already typed, simply add the missing final single or double quote:
bash$ git commit -m 'small changes > ' [main 0badd09] 736 files changed, 136756 insertions(+) bash$ _ Just to reiterate, Git and your editor are two different components (and so is your OS, your shell, your terminal, your programming language(s), etc). When you first get started, it's probably confusing and distracting to figure out which part controls which behavior. Down the line, this is how you end up with an extremely flexible and customizable and thus extremely efficient personal environment.
(On Windows, Git commonly comes bundled with Bash because at the time they started to figure things out, there was no sane native shell for Windows. These days, things are slightly different, to the extent that "sane" and Windows can be used in the same sentence without negations or complex qualifiers, but it probably doesn't make sense to go back and start over with a different baseline.)
-m?