ChatGPT解决这个技术问题 Extra ChatGPT

Git commit in terminal opens VIM, but can't get back to terminal

Trying to learn GitHub at the moment and doing this Git essentials tutorial over at nettuts. I'm on the lesson about making commits.

The teacher types git commit and it opens VIM as his editor (I'd also like to know how to make it open up in Sublime Text 2 instead) anyways it opens in VIM and I add in 1 line saying this is my first commit and hit save.

Next it then prompts me to save the output to the desktop, something I did not see in his screencast. Now I'm still in VIM and not sure how to get back to 'normal' terminal :(

I couldn't figure it out so I just exited the terminal and relaunched it, did git commit again and had some warning messages about duplicates! Not sure if I need to (E)edit anyways or (A)abort.

git status

https://i.stack.imgur.com/OoMYb.png

vim

https://i.stack.imgur.com/d4bbf.png

message when I reopen terminal and do git commit again

https://i.stack.imgur.com/wIZ30.png

f you just want to know how to save and exit vim, it's :wq
same problem here... as soon as I try to commit, the terminal opens some kind of editor that I can't quit out of. Very annoying!
@Kokodoko yeah I just commit with git commit -m 'my message' now, that's it :) no need for an editor, never needed to use 1, only needed 1 liners.
@LeonGaban short commit messages are okay for the first commit but from them on you should try to adopt the technique of having a short subject and then detailing what actually happened in that commit.
@LeonGaban you are amazing

G
GGJON

To save your work and exit press Esc and then :wq (w for write and q for quit).

Alternatively, you could both save and exit by pressing Esc and then :x

To set another editor run export EDITOR=myFavoriteEdioron your terminal, where myFavoriteEdior can be vi, gedit, subl(for sublime) etc.


+1 on explaining the command sequence and in the process showing how to switch editors if needed (but seriously, why would anyone want to use an editor other than vim :)
N.B. A simple :x save and quit vim it's a bit faster than :wq ;)
Te set the editor permanently you can use: git config --global core.editor myFavoriteEditor
esc key does nothing for me. What is this cryptic commands, is this 2016 or 1996? Incredible...
Totally doesn't work. Yes I entered a commit message. Vim sucks.
P
Philipp Kyeck

not really the answer to the VIM problem but you could use the command line to also enter the commit message:

git commit -m "This is the first commit"

l
lesderid

You need to return to normal mode and save the commit message with either

<Esc>:wq

or

<Esc>:x

or

<Esc>ZZ

The Esc key returns you from insert mode to normal mode. The :wq, :x or ZZ sequence writes the changes and exits the editor.


Nope... the esc key does nothing. I am stuck in "Merge branch master of ..." Please enter a commit message to explain why this merge is necessary.
Did you enter a commit message? What happens when you press <Esc>:wq?
In my case nothing happens. What is this cryptic commands, is this 2016 or 1996?
@Homo-Erectus - I started using vim some 4 years ago and my only regret is I didn't started earlier. I don't consider it time wasted, you should try it. It does have a steep learning curve mind you but it will be well worth it. As for the commands, I don't have much to add. Type , type :, type x and that should be it.
@oyalhi It is never late to start using vim
J
Jani Hartikainen

Simply doing the vim "save and quit" command :wq should do the trick.

In order to have Git open it in another editor, you need to change the Git core.editor setting to a command which runs the editor you want.

git config --global core.editor "command to start sublime text 2"


Thanks for the tip on setting the editor to sublime text. I did run into one problem though, I had to set a --wait flag: git config --global core.editor "subl --wait". This prevents Aborting commit due to empty commit message.
m
mhatch

This is in answer to your question...

I'd also like to know how to make it open up in Sublime Text 2 instead

For Windows:

git config --global core.editor "'C:/Program Files/Sublime Text 2/sublime_text.exe'"

Check that the path for sublime_text.exe is correct and adjust if needed.

For Mac/Linux:

git config --global core.editor "subl -n -w"

If you get an error message such as:

error: There was a problem with the editor 'subl -n -w'.

Create the alias for subl

sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

Again check that the path matches for your machine.

For Sublime Text simply save cmd S and close the window cmd W to return to git.