如何跳过“git commit --amend”中的提交消息步骤?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5307417/
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 skip the commit message step in "git commit --amend"?
提问by nfm
I'm running a very rapid code-compile-test loop where I am amending changes to my commits far more often than not.
我正在运行一个非常快速的代码编译测试循环,我经常修改提交的更改。
For example:
例如:
# Make some changes
$ git commit -m "Added feature X"
# Compile, test
# Fix bugs
$ git commit -a --amend
I usually want the same commit message after I fix my bugs. Is there a way to make git skip firing up my EDITOR
and just use the original commit message?
我通常在修复错误后想要相同的提交消息。有没有办法让 git 跳过我的启动EDITOR
而只使用原始提交消息?
回答by Adam Dymitruk
You can just add --no-edit
to use the last message. This option existed since 2005 but only recently has been enabled for the --amend
option.
您可以添加--no-edit
以使用最后一条消息。此选项自 2005 年以来就存在,但直到最近才为该--amend
选项启用。
The other way is to add -C HEAD
to the commit command with amend option. This allows you to not just use the current commit's message but you can specify any other reference you like, so it's worth remembering it.
另一种方法是-C HEAD
使用修改选项添加到提交命令。这使您不仅可以使用当前提交的消息,还可以指定您喜欢的任何其他引用,因此值得记住它。
This is particularly useful when constructing a commit from various places in history and using one of those commit's messages. For example:
这在从历史中的各个位置构建提交并使用这些提交的消息之一时特别有用。例如:
git checkout feature1^^ -- database/table1.sql
git checkout feature1^^^^ -- logger.py
git add -A && git commit -C feature1
which would just use 2 commits from a feature1 and use the commit message from the last commit to feature1 - if that was a good description.
这将只使用来自 feature1 的 2 次提交,并使用从最后一次提交到 feature1 的提交消息 - 如果这是一个很好的描述。
回答by user2718704
You can also use
你也可以使用
--reuse-message=<commit>
Take an existing commit object, and reuse the log message and the authorship
information (including the timestamp) when creating the commit.
Which allow you to use previous commit messages. This can also be part of a script or git alias.
这允许您使用以前的提交消息。这也可以是脚本或 git 别名的一部分。
回答by Vlad Isajkin
git commit --amend --reuse-message HEAD
will reuse message from last commit
将重用上次提交的消息
回答by Dong Thang
Since git 1.7.9 version you can also use git commit --amend --no-edit
由于 git 1.7.9 版本你也可以使用 git commit --amend --no-edit