简体   繁体   English

终端中的 Git 提交打开 VIM,但无法返回终端

[英]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.目前正在尝试学习 GitHub,并在 nettuts 上完成此Git 基础教程 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.老师输入git commit并打开 VIM 作为他的编辑器(我也想知道如何让它在Sublime Text 2 中打开)无论如何它在 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!我无法弄清楚,所以我只是退出终端并重新启动它,再次执行 git commit 并收到一些关于重复项的警告消息! Not sure if I need to (E)edit anyways or (A)abort .不确定我是否需要(E)edit(A)abort

git status状态

在此处输入图片说明

vim vim

在此处输入图片说明

message when I reopen terminal and do git commit again消息时,我重新打开终端,做混帐再犯

在此处输入图片说明

To save your work and exit press Esc and then : w q (w for write and q for quit).要保存您的工作并退出,请按Esc ,然后按: w q (w 表示写入,q 表示退出)。

Alternatively, you could both save and exit by pressing Esc and 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可以是vigeditsubl (用于 sublime)等。

不是 VIM 问题的真正答案,但您可以使用命令行也输入提交消息:

git commit -m "This is the first commit"

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. Esc键将您从插入模式返回到正常模式。 The :wq , :x or ZZ sequence writes the changes and exits the editor. :wq , :xZZ序列写入更改并退出编辑器。

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 在另一个编辑器中打开它,您需要将 Git core.editor设置更改为运行所需编辑器的命令。

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

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 sublsubl创建别名

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。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM