如何跳过“ git 提交——修改”中的提交消息步骤?

我正在运行一个非常快速的代码编译-测试循环,在这个循环中,我经常修改对提交的更改。

例如:

# Make some changes
$ git commit -m "Added feature X"
# Compile, test
# Fix bugs
$ git commit -a --amend

在修复 bug 之后,我通常需要相同的提交消息。有没有一种方法可以让 git 跳过启动我的 EDITOR,只使用原始的提交消息?

14224 次浏览

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.

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.

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.

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 commit --amend --reuse-message HEAD

will reuse message from last commit

Since git 1.7.9 version you can also use git commit --amend --no-edit