我有两个分行:
Branch1: (old) A B C D E F G H (new)
Branch2: (old) A B D E F (new)
注意,C 从分支 2 中删除,然后 G 和 H 被添加到分支 1
我想在 Branch2 上对 Branch1 进行变基,但我不希望 C 重新出现,因为它已从 Branch2 中删除。我只想快进从 Branch2 推送到 Branch1。重申一下,C 必须从历史中消失。
我的失败方法:
git checkout Branch1
git rebase Branch2
Branch1: (old) A B D E F C G H (new)
什么不起作用:
git rebase --onto Branch2 F G
git cherry-pick F G
我主要是在寻找某种方法来告诉 git rebase 仅选择快进提交。可以吗?
一种方法是以某种方式跟踪
Branch1
历史记录中已审查并集成或丢弃的点,然后用它来运行 git rebase --onto Branch2 <that_point> Branch1
。
一个例子可以是保留对该提交的引用,例如
git branch integration/Branch1 <F>
(<- meaning "commit F on Branch1")git update-ref --create-reflog -m "<some message for your reflog>" \
refs/integration/Branch1 <F>
当您在 Branch2 上集成新提交时,您应该更新该引用。 假设您在 Branch2 上包含提交
G
:
git branch -f integration/Branch1 G
git update-ref --create-reflog -m "<some message for your reflog>" \
refs/integration/Branch1 <G>
当您想要重新设置 Branch1 的基础(或至少尝试这样做)时,您可以使用该名称:
git rebase --onto Branch2 integration/Branch1 Branch1
如果成功,您应该更新“集成”参考:
*
git branch -f integration/Branch1 Branch2
或
*
git update-ref --create-reflog -m "<some message for your reflog>" \
refs/integration/Branch1 Branch2