GIT rebase 提交到顶部和底部

问题描述

我有 3 个分店。 A、B 和 X

    A has a commit - commit A
    B has a commit - commit B
    X has a commit - commit X

我想将 A 和 B 变基为 X

     A branch's commit should be top of X branch's commit
     B branch's commit should be bottom of X branch's commit 

最终提交日志应如下所示

    commit A
    commit X
    commit B

请解释我可以得到上述最终结果的步骤

解决方法

假设 git cherry-pick 是共同祖先,我会用 git rebase 而不是 main 这样做:

git checkout B
git cherry-pick main..X
git branch -f X
git cherry-pick main..A
git branch -f A

不管每个分支是否只包含一个提交或多个提交,这些都有效。如果 XA 中只有一次提交,您可以删除 main.. 部分。