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



我有两个分支

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,但不起作用(如前所述(

如果需要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:的提交C时重新设置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。不要使用范围;将提交压缩为一个。