git commit --amend 不要求消息

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

git commit --amend without asking for message

gitgit-commitamend

提问by talles

From time to time I find myself commit-amendingusing the same message.

有时我发现自己使用相同的消息进行提交修改

Typically, I do:

通常,我这样做:

  1. Add my changes to staging area.
  2. Do git commit --amend.
  3. Wait for the text editor to open.
  4. Save and close it (without changing the message).
  1. 将我的更改添加到暂存区。
  2. git commit --amend
  3. 等待文本编辑器打开。
  4. 保存并关闭它(不更改消息)。

There is anyway to tell git that I don't want to change the commit message (skipping the step of opening my text editor and saving the message)? Like:

无论如何要告诉 git 我不想更改提交消息(跳过打开文本编辑器并保存消息的步骤)?喜欢:

  1. Add my changes to staging area.
  2. Tell git to amend my staging area to the last commit without asking me for another message.
  1. 将我的更改添加到暂存区。
  2. 告诉 git 将我的暂存区修改为最后一次提交,而不要求我提供另一条消息。


I know I can avoid git firing up my text editor by doing git commit --amend -m "<message>". But this way I would have to retype the message.

我知道我可以通过执行 .gitignore 来避免 git 启动我的文本编辑器git commit --amend -m "<message>"。但是这样我就必须重新输入消息。

回答by Rob Bajorek

Try git commit --amend --no-edit.

试试git commit --amend --no-edit

回答by gylaz

This will amend the latest commit, using that same message, in one command:

这将在一个命令中使用相同的消息修改最新的提交:

git commit --amend -C HEAD