将 git commit -a 与 vim 一起使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6098742/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:58:31  来源:igfitidea点击:

Using git commit -a with vim

gitvim

提问by Jean

I'm new with git, so I decided to learn git using the tutorials of github. The third chapter said:

我是 git 新手,所以我决定使用 github 的教程来学习 git。第三章说:

"For this first example we'll modify the README file to add ourselves as an author on the project. So we simply edit the file. Now we want to commit that change, so we run the git commit -acommand."

“对于第一个示例,我们将修改 README 文件以将自己添加为项目的作者。因此我们只需编辑文件。现在我们要提交该更改,因此我们运行git commit -a命令。”

When I use the git commit -acommand, the console opens a vim and I wrote my message, but I don't know how to close this vim editor from the console. How do I save the message and close vim?

当我使用git commit -a命令时,控制台打开一个vim,我写了我的消息,但我不知道如何从控制台关闭这个vim编辑器。如何保存消息并关闭 vim?

回答by abcd

  1. In vim, you save a file with :wEnterwhile in the normal mode (you get to the normal mode by pressing Esc).
  2. You close your file with :qwhile in the normal mode.
  1. 在 vim 中,您可以:wEnter在正常模式下使用while保存文件(按 进入正常模式Esc)。
  2. :q在正常模式下关闭文件。

You can combine both these actions and do Esc:wqEnterto save the commit and quit vim.

您可以结合这两个操作并执行Esc:wqEnter保存提交并退出 vim。

As an alternate to the above, you can also press ZZwhile in the normal mode, which will save the file and exit vim. This is also easier for some people as it's the same key pressed twice.

作为上述的替代方法,您也可以ZZ在正常模式下按,这将保存文件并退出 vim。这对某些人来说也更容易,因为它是按两次相同的键。

回答by Uku Loskit

Instead of trying to learn vim, use a different easier editor (like nano, for example). As much as I like vim, I do not think using it in this case is the solution. It takes dedication and time to master it.

与其尝试学习 vim,不如使用其他更简单的编辑器(例如 nano)。尽管我喜欢 vim,但我不认为在这种情况下使用它是解决方案。掌握它需要奉献精神和时间。

git config core.editor "nano"

回答by eckes

See this thread for an explanation: VIM for Windows - What do I type to save and exit from a file?

请参阅此线程以获取解释:VIM for Windows - 我输入什么来保存和退出文件?

As I wrote there: to learn Vimming, you could use one of the quick reference cards:

正如我在那里写的:要学习 Vimming,您可以使用其中一张快速参考卡:

Also note How can I set up an editor to work with Git on Windows?if you're not comfortable in using Vim but want to use another editor for your commit messages.

另请注意如何设置编辑器以在 Windows 上使用 Git?如果你不习惯使用 Vim 但想使用另一个编辑器来处理你的提交消息。

If your commit message is not too long, you could also type

如果你的提交信息不是太长,你也可以输入

git commit -a -m "your message here"

回答by cdunn2001

The better question is: How do I interrupt the commit when I quit vim?

更好的问题是:当我退出 vim 时如何中断提交?

There are 2 ways:

有2种方式:

  1. :cqor :cquit
  2. Delete all lines of the commit message, including comments, and then :wq
  1. :cq或者 :cquit
  2. 删除提交消息的所有行,包括注释,然后 :wq

Either way will give git an error code, so it will not proceed with the commit. This is particularly useful with git commit --amend.

无论哪种方式都会给 git 一个错误代码,所以它不会继续提交。这对于git commit --amend.

回答by Abizern

Try ZZto save and close. Here is a bit more infoon using vim with Git

尝试ZZ保存并关闭。 这里有更多关于在 Git 中使用 vim 的信息

回答by chrisjlee

To exit hitting :q will let you quit.

要退出点击 :q 会让你退出。

If you want to quit without saving you can hit :q!

如果你想不保存就退出,你可以点击 :q!

A google search on "vim cheatsheet" can provide you with a reference you should print out with a collection of quick shortcuts.

在“vim 备忘单”上的谷歌搜索可以为您提供参考,您应该打印出一组快速快捷方式。

http://www.fprintf.net/vimCheatSheet.html

http://www.fprintf.net/vimCheatSheet.html