git: 如何在分支合并后变基并保留合并提交的更改

git: how to rebase a branch after it was merged and keep the merge commit's changes

我有这样的历史:

A - B - M
 \    /
    C 

A、B、M 是 master,C 在功能分支上。

我犯了两个错误:

  1. 我之前没有意识到公司远程不接受合并提交。
  2. 除了简单地解决冲突之外,我在合并提交中更改了很多东西。

我想变基,所以它看起来像 A - B - C - M,C - M 可能压在一起。

我只找到 one question on the internet which actually looked quite similar to my case,唯一的回应是 "merge is fine"。

我承认我仍然不是 100% 熟悉变基语法,但是我告诉 git 变基的任何组合,有或没有 -p and/or -i,它要么说没有什么可以变基(noop),要么说它不起作用。

似乎合乎逻辑的选择是踩 C 和 rebase -ip master,但它并没有达到我的预期。

鉴于这段历史:

A - B - M
  \    /
    C 

在 M,你软重置到 B,然后提交,然后你将得到 A - B - M',这似乎是你想要的:

git checkout M
git reset B
git commit

分支的内容将保持不变,none 这些命令改变了这一点,只有 C 从历史记录中删除,使其看起来像一个直分支。