终端中的 Git 提交打开 VIM,但无法返回终端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13507430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git commit in terminal opens VIM, but can't get back to terminal
提问by Leon Gaban
Trying to learn GitHub at the moment and doing this Git essentials tutorialover at nettuts. I'm on the lesson about making commits.
目前正在尝试学习 GitHub,并在 nettuts 上完成此Git 基础教程。我正在学习关于提交的课程。
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 Text2 instead) anyways it opens in VIM and I add in 1 line saying this is my first commit and hit save.
老师输入git commit
并打开 VIM 作为他的编辑器(我也想知道如何让它在Sublime Text2 中打开)无论如何它在 VIM 中打开,我添加了 1 行说这是我的第一次提交并点击保存.
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 :(
接下来,它提示我将输出保存到桌面,这是我在他的截屏视频中没有看到的。现在我还在 VIM 中,不知道如何回到“正常”终端:(
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 commit 并收到一些关于重复项的警告消息!不知道如果我需要(E)edit
反正或者(A)abort
。
git status
状态
vim
vim
messagewhen I reopen terminal and do git commit again
消息当我重新打开终端,做混帐再犯
回答by Gille
To save your work and exit press Escand then :wq(w for write and q for quit).
要保存您的工作并退出,请按Esc然后:wq(w 表示写入,q 表示退出)。
Alternatively, you could both save and exit by pressing Escand then :x
或者,您可以通过按Esc然后保存并退出:x
To set another editor run export EDITOR=myFavoriteEdior
on your terminal, where myFavoriteEdior
can be vi
, gedit
, subl
(for sublime) etc.
要export EDITOR=myFavoriteEdior
在终端上运行另一个编辑器,myFavoriteEdior
可以是vi
, gedit
, subl
(用于 sublime)等。
回答by pkyeck
not really the answer to the VIM problem but you could use the command line to also enter the commit message:
不是 VIM 问题的真正答案,但您可以使用命令行也输入提交消息:
git commit -m "This is the first commit"
回答by Lieven Keersmaekers
You need to return to normalmode and save the commit message with either
您需要返回正常模式并使用以下任一方式保存提交消息
<Esc>:wq
or
或者
<Esc>:x
or
或者
<Esc>ZZ
The Esckey returns you from insertmode to normalmode. The :wq, :xor ZZsequence writes the changes and exits the editor.
该Esc键将您从插入模式返回到正常模式。的:wq,:x或ZZ顺序写入更改并退出编辑器。
回答by Jani Hartikainen
Simply doing the vim "save and quit" command :wq
should do the trick.
只需执行vim“保存并退出”命令:wq
就可以解决问题。
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 在另一个编辑器中打开它,您需要将 Gitcore.editor
设置更改为运行所需编辑器的命令。
git config --global core.editor "command to start sublime text 2"
git config --global core.editor "command to start sublime text 2"
回答by 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
我还想知道如何在 Sublime Text 2 中打开它
For Windows:
对于 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.
检查路径sublime_text.exe
是否正确,并根据需要进行调整。
For Mac/Linux:
对于 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'.
错误:编辑器“subl -n -w”有问题。
Create the alias for subl
创建别名 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.
对于 Sublime Text,只需保存cmd S
并关闭窗口cmd W
即可返回 git。