如何在樱桃选择中保持合并提交的分歧形式?

问题描述 投票:0回答:2

我想挑选一系列提交,其中有一个合并提交,当我想挑选我的提交时,这个合并提交只是以线性形式挑选,但我想保持其发散表单并查看哪些提交是此合并提交的父级,但这种情况在由cherry-pick创建的线性历史中是不可能的,所以我想知道是否可以在cherry-pick中保持我们的历史发散,或者如果不可能,git还有其他替代方法吗?

我使用的命令:

git cherry-pick (commit C hash)~1..(commit F hash)   (my head is pointing to test1)

图表:

A--B--C--E--F--K (master)               Current history
    \  \   /
     J   D (test2)
    (test1)
A--B--C--E--F--K--T (master)             History after cherry-picking
    \  \   /
     J   D (test2)
      \
       C
        \
         D
          \
           E
            \
             F
             (test1)
A--B--C--E--F--K--T (master)             Expected history after cherry-picking
    \  \   /
     J   D (test2)
      \
       C
      / \
     D   E
      \   \ 
       \---F   
          (test1)
git cherry-pick
2个回答
1
投票

一种解决方案是交互式重组 (

git rebase -i
)。

 git rebase -i -r --onto J C~ F
 # The edit screen pops up. Just save and quit.

预期的历史是在独立的 HEAD 中创建的。然后用这个新的 HEAD 更新

test1

git update-ref refs/heads/test1 HEAD

提交 C、D、E 和 F 重新基于 J。

-r/--rebase-merges
指示保留合并提交结构。


0
投票

您正在寻找

git rebase --rebase-merges
:

git branch -f test1 F
git rebase --rebase-merges J test1
© www.soinside.com 2019 - 2024. All rights reserved.