GIT cherry pick all my commits that exists in one branch to another branch

我怕爱的太早我们不能终老 提交于 2019-12-11 14:18:39

问题


I have 2 branches A and B. Branch B was branched from branch A at some time and multiple users are committing to both branches. I want to cherry pick all my commits (that doesn't already exist in branch A) from branch B to branch A without the need to manually search for every single one. Is it somehow possible?

Thanks


回答1:


A more straight foreward way would be to use rebase --onto:

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

if your repo looks like this:

a - B - c - d - e -> master
      \      \
       \      f - g -> some-feature
        \
         h - i - j -> branch-to-move

the command

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

would result in

a - B - c - d - e -> master
             \
              f - g -> some-feature
                   \
                    h' - i' - j' -> branch-to-move



回答2:


Figured it out and made this PowerShell script:

$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(' ') }


来源:https://stackoverflow.com/questions/51437676/git-cherry-pick-all-my-commits-that-exists-in-one-branch-to-another-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!