将提交范围从一个分支应用到另一个分支

Apply range of commits from one branch to another

我有2个分支

a -- b -- c -- d -- e -- f -- g -- h     <-- master

a -- b -- c                              <-- Branch1
            

我需要将提交 e、f 和 g 应用到 Branch1

尝试过:

git rebase --onto gSha1 eSha1 hSha1 在 Branch1 上结帐后没有成功(如前所述

尝试使用 git cherry-pick eSha1^..gSha1 但它也不起作用(如前所述 here

如果你愿意 a -- b -- c -- e -- f -- g

来自

                           E---F---G  master
                          /            
                         D
                        /
               A---B---C  Branch1
git rebase --onto branch1 dSha1 gSha1

会给你

                         E'--F'--G'  HEAD
                        /              
                       | D---E---F---G  master
                       |/
               A---B---C  Branch1

接下来将 Branch1 设置为 HEAD:

git branch -f Branch1 HEAD
                         D---E---F---G  master
                        /
               A---B---C---E'--F'--G' Branch1

备选

将 Branch1 设置为 master 并在没有 D 的情况下对 Branch1 进行变基:

git co Branch1
git reset --hard master
git rebase --onto cSha1 dSha1 Branch1

如果你愿意 a -- b -- c -- d -- e -- f -- g (第一个问题)

切换到 Branch1

git checkout Branch1

然后将 Branch1 设置为 g

git reset --hard gSha1

你来了 你可以推送或继续

结帐 branch1,然后 git cherry-pick e f g。不要使用范围;将提交压缩为一个。