如何从 Windows cmd 保存 git commit 消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13340329/
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
How to save a git commit message from windows cmd?
提问by Hymanson Publick
I run git from the command line.
我从命令行运行 git。
How does one save the commit message?
如何保存提交消息?
I mean what keys should I press to go past this screen:
我的意思是我应该按什么键才能通过这个屏幕:
回答by Ikke
You are inside vim. To save changes and quit, type:
你在vim里面。要保存更改并退出,请键入:
<esc> :wq <enter>
That means:
这意味着:
- Press Escape. This should make sure you are in command mode
- type in
:wq
- Press Return
- 按Escape。这应该确保您处于命令模式
- 输入
:wq
- 按 Return
An alternative that stdcall in the comments mentions is:
评论中提到的 stdcall 的另一种选择是:
- Press Escape
- Press shift+Zshift+Z(capital
Z
twice).
- 按 Escape
- 按shift+ Zshift+ Z(大写
Z
两次)。
回答by Martin G
I believe the REALanswer to this question is an explanation as to how you configure what editor to use by default, if you are not comfortable with Vim.
我相信这个问题的真正答案是关于如何配置默认使用的编辑器的解释,如果您对 Vim 不满意。
This is how to configure Notepad for example, useful in Windows:
例如,这是如何配置记事本,在 Windows 中很有用:
git config --global core.editor "notepad"
Gedit, more Linux friendly:
Gedit,对 Linux 更友好:
git config --global core.editor "gedit"
You can read the current configuration like this:
您可以像这样读取当前配置:
git config core.editor
回答by Felipe Cabargas
You can also commit with git commit -m "Message goes here"
That's easier.
您还可以使用git commit -m "Message goes here"
更简单的方式进行提交。
回答by Zacarias Bendeck
Press Shift-zz. Saves changes and Quits. Escape didn't work for me.
按 Shift-zz。保存更改并退出。逃跑对我不起作用。
I am using Git Bash in windows. And couldn't get past this either. My commit messages are simple so I dont want to add another editor atm.
我在 Windows 中使用 Git Bash。也无法克服这一点。我的提交信息很简单,所以我不想添加另一个编辑器 atm。
回答by ScriptCode
If you enter git commit
but omit to enter a comment using the –m
parameter, then Git will open up the default editor for you to edit your check-in note. By default that is Vim. Now you can do two things:
如果您git commit
使用–m
参数输入但省略输入注释,则 Git 将打开默认编辑器供您编辑签到注释。默认情况下是 Vim。现在你可以做两件事:
Alternative 1 – Exit Vim without entering any comment and repeat
备选方案 1 – 退出 Vim 而不输入任何注释并重复
A blank or unsaved comment will be counted as an aborted attempt to commit your changes and you can exit Vim by following these steps:
空白或未保存的注释将被视为提交更改的尝试中止,您可以按照以下步骤退出 Vim:
Press Escto make sure you are not in edit mode (you can press Escseveral times if you are uncertain)
Type
:q!
enter
(that is, colon, letter q, exclamation mark, enter), this tells Vim to discard any changes and exit)
Git will then respond:Aborting commit due to empty commit message
and you are once again free to commit using:
git commit –m "your comment here"
按下Esc以确保您没有处于编辑模式(Esc如果不确定,可以按下几次)
输入
:q!
enter
(即,冒号、字母 q、感叹号、回车),这告诉 Vim 放弃任何更改并退出)
Git 将响应:由于空提交消息而中止提交
您可以再次自由地使用:
git commit –m "your comment here"
Alternative 2 – Use Vim to write a comment
备选方案 2 – 使用 Vim 写评论
Follow the following steps to use Vim for writing your comments
按照以下步骤使用 Vim 编写您的评论
- Press ito enter Edit Mode (or Insert Mode).
That will leave you with a blinking cursor on the first line. Add your comment. Press Escto make sure you are not in edit mode (you can press Esc several time if you are uncertain) - Type
:wq
enter
(that is colon, letter w, letter q, enter), this will tell Vim to save changes and exit)
- 按i进入编辑模式(或插入模式)。
这将使您在第一行上有一个闪烁的光标。添加您的评论。按Esc以确保您不在编辑模式(如果不确定,可以按几次 Esc) - 输入
:wq
enter
(即冒号、字母 w、字母 q、回车),这将告诉 Vim 保存更改并退出)
Response from https://blogs.msdn.microsoft.com/kristol/2013/07/02/the-git-command-line-101-for-windows-users/
来自https://blogs.msdn.microsoft.com/kristol/2013/07/02/the-git-command-line-101-for-windows-users/ 的回复