使用 Vim 输入 Git 提交消息的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5599122/
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
Problems with entering Git commit message with Vim
提问by aTei
OS: Windows
操作系统:Windows
I write
我写的
$ git commit
then
然后
"# Please enter the commit message"
"#请输入提交信息"
I write some text, like
我写了一些文字,比如
"Form validation added"
“添加了表单验证”
Press Enter and not commited. Then i press Shift+Enter, Ctrl+Enter, Alt+Enter - still not commited.
按 Enter 并没有提交。然后我按 Shift+Enter、Ctrl+Enter、Alt+Enter - 仍然没有提交。
I think its stupid trouble, but What i must to do?
我认为这是愚蠢的麻烦,但我必须做什么?
回答by mousio
If it is VIM for Windows, you can do the following:
如果是VIM for Windows,可以进行如下操作:
- enter your message following the presented guidelines
- press Escto make sure you are out of the insert mode
- then type
:wq
EnterorZZ
.
- 按照提供的指南输入您的消息
- 按下Esc以确保您已退出插入模式
- 然后输入
:wq
Enter或ZZ
。
Note that in VIM there are often several ways to do one thing. Here there is a slight difference though. :wq
Enteralways writes the current file before closing it, while ZZ
, :x
Enter, :xi
Enter, :xit
Enter, :exi
Enterand :exit
Enteronly write it if the document is modified.
All these synonyms just have different numbers of keypresses.
请注意,在 VIM 中,通常有多种方法可以做一件事。不过,这里略有不同。:wq
Enter总是在关闭之前写入当前文件,而ZZ
, :x
Enter, :xi
Enter, :xit
Enter,:exi
Enter并且:exit
Enter仅在文档被修改时写入。
所有这些同义词只是有不同数量的按键。
回答by Matt Greer
I am assuming you are using msys git. If you are, the editor that is popping up to write your commit message is vim. Vim is not friendly at first. You may prefer to switch to a different editor. If you want to use a different editor, look at this answer: How do I use Notepad++ (or other) with msysgit?
我假设您正在使用 msys git。如果是,则弹出来编写提交消息的编辑器是 vim。Vim 一开始并不友好。您可能更喜欢切换到不同的编辑器。如果您想使用不同的编辑器,请查看此答案:How do I use Notepad++ (or other) with msysgit?
If you want to use vim, type i
to type in your message. When happy hit ESC. Then type :wq
, and git will then be happy.
如果您想使用 vim,请键入i
以输入您的消息。开心的时候按ESC。然后输入:wq
,然后 git 会很高兴。
Or just type git commit -m "your message here"
to skip the editor altogether.
或者只需键入git commit -m "your message here"
即可完全跳过编辑器。
回答by Tony
Have you tried just going: git commit -m "Message here"
你有没有试过: git commit -m "Message here"
So in your case:
所以在你的情况下:
git commit -m "Form validation added"
After you've added your files of course.
当然,在您添加文件之后。
回答by Emil Sit
Typically, git commit
brings up an interactive editor (on Linux, and possibly Cygwin, determined by the contents of your $EDITOR
environment variable) for you to edit your commit message in. When you save and exit, the commit completes.
通常,git commit
会打开一个交互式编辑器(在 Linux 上,也可能在 Cygwin 上,由$EDITOR
环境变量的内容决定)供您编辑提交消息。当您保存并退出时,提交完成。
You should make sure that the changes you are trying to commit have been added to the Git index; this determines what is committed. See http://gitref.org/basic/for details on this.
您应该确保您尝试提交的更改已添加到 Git 索引中;这决定了承诺的内容。有关这方面的详细信息,请参阅http://gitref.org/basic/。
回答by Matt Spradley
You can change the comment character to something besides # like this:
您可以将注释字符更改为 # 之外的内容,如下所示:
git config --global core.commentchar "@"