git commit --amend
将为最近的提交添加阶段性更改。由于它合并了你的两个,我怀疑没有两个提交,而是一个。
手册页解释了这一点:
--amend
Replace the tip of the current branch by creating a new commit. The
recorded tree is prepared as usual (including the effect of the -i and
-o options and explicit pathspec), and the message from the original
commit is used as the starting point, instead of an empty message, when
no other message is specified from the command line via options such as
-m, -F, -c, etc. The new commit has the same parents and author as the
current one (the --reset-author option can countermand this).
It is a rough equivalent for:
$ git reset --soft HEAD^
$ ... do something else to come up with the right tree ...
$ git commit -c ORIG_HEAD
but can be used to amend a merge commit.
You should understand the implications of rewriting history if you
amend a commit that has already been published. (See the "RECOVERING
FROM UPSTREAM REBASE" section in git-rebase[1].)
因为您描述了处理多个提交,所以我将解释上述描述的工作流程如何改为:
A--B (origin/dev) (dev)
编辑文件,然后添加暂存 ( git add -u
):
$ git commit # edit a good message (see below)
A--B (origin/dev)
\
C (dev)
现在重复:
$ git commit # edit another awesome message (see below)
A--B (origin/dev)
\
C--D (dev)
但是现在你意识到提交 C 有一个错误的提交信息。所以我们做一个变基:
$ git rebase -i origin/dev
在编辑器中,您将看到提交 C 和 D 及其主题行和关键字pick
。找到您要修复的提交并将其更改pick
为reword
然后保存文件。
git 将打开另一个编辑器并让您修复提交消息。保存并继续。
关于提交消息的注释(因为我试图传播这个词):
https://thoughtbot.com/blog/5-useful-tips-for-a-better-commit-message
Capitalized, short (50 chars or less) summary
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body. The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.
Write your commit message in the imperative: "Fix bug" and not "Fixed bug"
or "Fixes bug." This convention matches up with commit messages generated
by commands like git merge and git revert.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, followed by a
single space, with blank lines in between, but conventions vary here
- Use a hanging indent