GIT cherry从一个分支中存在的所有提交中选择到另一个分支



我有两个分支A和B。分支B在某个时间从分支A分支出来,多个用户正在提交这两个分支。我想把我的所有提交(在分支A中还不存在(从分支B挑选到分支A,而不需要手动搜索每一个。这有可能吗?

感谢

一种更直接的方法是使用rebase--onto:

git rebase --onto target-branch [LAST_COMMON_COMMIT_BEFORE_BRANCH] branch-to-move

如果你的回购看起来像这样:

a - B - c - d - e -> master
      
      f - g -> some-feature

h - i - j -> branch-to-move

命令

git rebase --onto some-feature B branch-to-move

会导致

a - B - c - d - e -> master

f - g -> some-feature

h' - i' - j' -> branch-to-move

想好了并制作了这个PowerShell脚本:

$Source = Read-Host -Prompt 'Enter Source branch: '
$Target = Read-Host -Prompt 'Enter Target branch: '
cd C:project
git log $Source --not $Target --cherry --author=my@ema.il --author-date-order --reverse | 
Select-String -Pattern "commit" |
ForEach-Object { git cherry-pick -x $_.ToString().split("+")[-1].Trim(' ') }