Git - 如何关闭提交编辑器?

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

Git - How to close commit editor?

gitcommand-lineversion-control

提问by aniskhan001

I'm new to git and learning from a PDF. I just executed a command $ git commitand it opens a new editor. But I'm trying to close that new commit editor. How to do this? I'm using git on windows.

我是 git 新手,正在从 PDF 中学习。我刚刚执行了一个命令$ git commit,它打开了一个新的编辑器。但我正在尝试关闭那个新的提交编辑器。这该怎么做?我在 Windows 上使用 git。

回答by tpg2114

Save the file in the editor. If it's Emacs: CTRLXCTRLSto save then CTRLXCTRLCto quit or if it's vi: :wq

将文件保存在编辑器中。如果是 Emacs:CTRLXCTRLS保存然后CTRLXCTRLC退出,或者如果是 vi::wq

Press escfirst to get out from editing. (in windows/vi)

esc首先按退出编辑。(在 windows/vi 中)

回答by Marc Compte

Had troubles as well. On Linux I used Ctrl+X(and Yto confirm) and then I was back on the shell ready to pull/push.

也遇到了麻烦。在 Linux 上,我使用了Ctrl+ X(并Y确认),然后我又回到了准备拉/推的 shell 上。

On Windows GIT BashCtrl+Xwould do nothing and found out it works quite like vi/vim. Press ito enter inline insert mode. Type the description at the very top, press escto exit insert mode, then type :x!(now the cursor is at the bottom) and hit enterto save and exit.

Windows 上,GIT BashCtrl+X什么也不做,但发现它的工作方式与 vi/vim 非常相似。按i进入内嵌插入模式。在最顶部输入说明,按下esc退出插入模式,然后输入:x!(现在光标在底部)并点击enter保存并退出。

If typing :q!instead, will exit the editor without saving (and commit will be aborted)

如果:q!改为键入,将退出编辑器而不保存(并且提交将被中止)

回答by chandan gupta

After writing commit message, just press EscButton and then write :wqor :wq!and then Enterto close the unix file.

写入提交消息后,只需按Esc按钮,然后写入:wq:wq! 然后Enter关闭 unix 文件。

回答by Martin G

Better yet, configure the editor to something you are comfortable with (gedit as an example):

更好的是,将编辑器配置为您喜欢的东西(以 gedit 为例):

git config --global core.editor "gedit"

You can read the current configuration like this:

您可以像这样读取当前配置:

git config core.editor

You can also add the commit message from the command line.

您还可以从命令行添加提交消息。

git commit -m "blablabla"

and the editor will not be opened in the first place.

并且编辑器不会首先打开。

回答by Mohammad Hashemi

After git commitcommand, you entered to the editor, so first hit ithen start typing. After committing your message hit Ctrl + cthen :wq

git commit命令,进入到编辑器,所以先打i然后开始打字。提交您的消息Ctrl + c后,然后:wq

回答by ggootz

Alternatives to Nano (might make your life easier):

Nano 的替代品(可能会让您的生活更轻松):

On Windows, use notepad. In command prompt type:

在 Windows 上,使用记事本。在命令提示符中键入:

git config core.editor notepad

git config core.editor notepad

On Ubuntu / Linux, use text editor (gedit). In terminal window type:

在 Ubuntu / Linux 上,使用文本编辑器 (gedit)。在终端窗口输入:

git config core.editor gedit

git config core.editor gedit

回答by Mariano Cali

I had this problem I received a ">" like prompt and I couldn't commit. I replace the " in the comment with ' and it works.

我遇到了这个问题,我收到了一个 ">" 之类的提示,但我无法提交。我用 ' 替换了评论中的 " 并且它起作用了。

I hope this help someone!

我希望这对某人有所帮助!

回答by Martin

As an alternative to 'save & quit', you can use git-commit's function git-commit-commit, by default bound to C-c C-c. It will save the file and close it. Afterwards, you still have to close emacs with C-x C-c, as mentioned before. I am currently trying to find out how to make emacs quit automatically.

作为“保存并退出”的替代方法,您可以使用 git-commit 的函数git-commit-commit,默认情况下绑定到C-c C-c. 它将保存文件并关闭它。之后,您仍然必须使用 关闭 emacs C-x C-c,如前所述。我目前正在尝试找出如何让 emacs 自动退出。

回答by dubfactor

Not sure the key combination that gets you there to the > prompt but it is not a bash prompt that I know. I usually get it by accident. Ctrl+C (or D) gets me back to the $ prompt.

不确定将您带到 > 提示符的组合键,但我知道它不是 bash 提示符。我通常是偶然得到的。Ctrl+C(或 D)让我回到 $ 提示。

回答by Siddhartha

Note that if you're using Sublime as your commit editor, you need the -n -wflags, otherwise git keeps thinking your commit message is empty and aborting.

请注意,如果您使用 Sublime 作为提交编辑器,则需要-n -wflags,否则 git 一直认为您的提交消息为空并中止。