如何在终端中的`git commit --amend`后确认更改?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28176813/
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 confirm changes after `git commit --amend` in Terminal?
提问by Bart?omiej Semańczyk
When I write git commit --amend
I get some kind of editor, where I can change the name of this commit. How to confirm and save my changes using keyboard?
当我写作时,git commit --amend
我会得到某种编辑器,我可以在其中更改此提交的名称。如何使用键盘确认和保存我的更改?
回答by Travis
Expanding on what William Pursell said, you probably ended up in vim. Save your changes and exit the editor by typing :
to enter a command, followed by wq
, then press enter. To exit vim without saving your changes do :q!
instead.
扩展 William Pursell 所说的内容,您可能最终使用了 vim。保存更改并通过输入:
命令退出编辑器wq
,然后按 ,然后按 Enter。要在不保存更改的情况下退出 vim,请改为执行:q!
。
To change this default to something you're more familiar with, you can set the EDITOR
variable to something of your choice (try nano
).
要将这个默认值更改为您更熟悉的内容,您可以将EDITOR
变量设置为您选择的内容(尝试nano
)。
Just put export EDITOR=nano
at the end of ~/.bash_profile
(create the file if you don't already have it) to get this behaviour for every new terminal session.
只需放在(如果您还没有文件,则创建文件)export EDITOR=nano
的末尾~/.bash_profile
即可为每个新的终端会话获取此行为。
Also, you could do git commit --amend -m 'Your message here'
without a need for an editor at all.
此外,您可以完全git commit --amend -m 'Your message here'
不需要编辑器。
回答by Martin G
Configure the editor like this (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 --amend -m "blablabla"
and the editor will not be opened at all.
并且编辑器根本不会打开。
回答by Sean Yun-Shiuan
It seems like this thread answers your question: Git - How to close commit editor?
这个线程似乎回答了您的问题:Git - 如何关闭提交编辑器?
Save the file in the editor. If it's Emacs: CTRLX CTRLS to save then CTRLX CTRLC > to quit or if it's vi: :wq
Press esc first to get out from editing. (in windows/vi)
将文件保存在编辑器中。如果是 Emacs: CTRLX CTRLS 保存然后 CTRLX CTRLC > 退出或者如果是 vi: :wq
先按 esc 退出编辑。(在 windows/vi 中)
回答by Scott Yang
Just follow the instructions on the lower part of the screen.
I remember it said that, press ^O
to write out, and then if you have changed anything, it will let's you enter the file name to write to. Just press enter
now.
只需按照屏幕下方的说明进行操作即可。我记得上面说过,按^O
写出来,然后如果你改变了什么,它会让你输入要写入的文件名。enter
现在就按。
NOTE THAT, ^O
means Ctrl+O
, and M-D
means Esc+D
on Ubuntu(as far as I know). This is what confuses us.
请注意,在 Ubuntu 上,^O
意味着Ctrl+O
和M-D
意味着Esc+D
(据我所知)。这就是让我们困惑的地方。
You can always use ^G
to read the help info.
您可以随时使用^G
阅读帮助信息。