使用 autosquash 重新定位不能按预期工作

rebasing with autosquash doesn't work as expected

我正在尝试使用 git-rebase 提供的 autosquash 选项压缩最后 3 次提交。我有以下历史:

* commit 78a7e4844fa32d2ef1bb7bd9b44c4a1b9551d31a (HEAD, new)
| Author: maxim koretskyi <mkoretskyi@company.com>
| Date:   Fri Feb 20 10:29:48 2015 +0200
|
|     squash! s3
|
* commit f25491cadc646baf14bd7e951245c6777230a1d7
| Author: maxim koretskyi <mkoretskyi@company.com>
| Date:   Fri Feb 20 10:29:42 2015 +0200
|
|     squash! s2
|
* commit b988237356ffb59752e49049d083c558373f9486
| Author: maxim koretskyi <mkoretskyi@company.com>
| Date:   Fri Feb 20 10:29:24 2015 +0200
|
|     squash! s1
|
* commit abbcdc833e5eaabe79681bd82087b4d7969e8599 (new1, ne, 9484)
| Author: maxim koretskyi <mkoretskyi@company.com>
| Date:   Wed Feb 18 18:21:58 2015 +0200
|
|     3

所以我想压缩带有前缀 squash! 的消息 s1s2s3 的提交。现在我发出以下命令:

$ git rebase -i abbcdc833 --autosquash

因此 git 打开一个包含以下内容的文本编辑器:

pick b988237 squash! s1
pick f25491c squash! s2
pick 78a7e48 squash! s3

但我希望它是这样的:

pick b988237 squash! s1
squash f25491c squash! s2
squash 78a7e48 squash! s3

我做错了什么?

来自文档,但强调我的:

When the commit log message begins with "squash! ..." (or "fixup! ..."), and there is a commit whose title begins with the same ..., automatically modify the todo list of rebase -i so that the commit marked for squashing comes right after the commit to be modified, and change the action of the moved commit from pick to squash (or fixup). Ignores subsequent "fixup! " or "squash! " after the first, in case you referred to an earlier fixup/squash with git commit --fixup/--squash.

您的第一个 squash!s3 作为其 ... 部分。因此,rebase 查找具有 s3 作为其 "title" 的提交(这从未在文档中定义,但它似乎意味着 "one-line description",即日志消息的第一行).列表中没有这样的提交。

继续第二个,我们发现了同样的问题,第三个也是如此。

如果您的第一个提交(标题为 s1)之后是一个标题为 squash! s1 的提交,该特定提交将得到一个 "squash" 字。

(请注意,git commit --fixup=<id>git commit --squash=<id> 将为您创建这种 "same title" 提交。"ignores subsequent" 内容是因为您可以在工作时执行此操作:

git add ...; git commit -m thing1
... edit ...
git add ...; git commit -m thing2
# now fix thing1 bug noticed while working on thing2
... edit ...
git add ...; git commit --no-edit --fixup=HEAD^
... edit/test some more, discover fixup was not complete
git add ...; git commit --no-edit --fixup=HEAD

在这种情况下,second 修正行是 fixup! fixup! thing1; rebase 再次查找 "title" 为 thing1 的提交。)