Git,如何 "force" 压缩 rebase

Git, how to "force" a squash rebase

我需要 "squash" 一起提交。通常我习惯做这样的事情:

git rebase -i HEAD~10

但是,现在我收到以下错误:

error: could not apply 2009972... fixes

When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort".

如您所见,git 假装我解决了所有的冲突。现在,我不想也无法解决任何冲突。

我需要的是一种方法来告诉 git 类似于:"Hey, I do not want to merge anything: just take all the tracked files in this branch - as they appear in the last commit/HEAD, discard/remove the previous 10 commits before the latest one, and finally "apply"these files as a new commit":

例如,假设这是所有提交哈希的列表:

1-2-3-4-5-6-7-8-9-10-11-12,其中 HEAD 指向 12。

我想 squash/remove/whatever 这个操作被称为包括 2-11 的所有提交,所以 git log 之后的最终结果给出:

1-12

其中操作前后的文件必须相同.

获取我需要的命令是什么?

最简单的解决方案(在中止当前变基之后)是:

$ git reset --soft HEAD~10

现在,您的 HEAD 已向后移动十个提交,但是 none 您的文件已更改:它们将全部显示为要提交的新更改。

然后,像往常一样提交它们。


这种方法的缺点是您在编写新提交消息时无法访问中间提交消息。

另一种方法是通过指定冲突解决策略他们的:

使原始 rebase -i 命令为您工作
$ git rebase -i -s theirs HEAD~10

首先要知道您是如何设法解决冲突的,这将很有趣,rebase -i 通常应该干净利落地应用。除非这十个提交中的一些本身是合并的?