gitgit-cherry-pick

git tool to cherry-pick branch


Do I need to write a shellscript for cherry-picking every commit of a branch (since merge-base origin/HEAD), or does that command exist?

I find myself opening gitk and counting the number of commits, with my finger on the screen, and then cherry-picking each one:

git cherry-pick origin/feature-branch~9
git cherry-pick origin/feature-branch~8
git cherry-pick origin/feature-branch~7
git cherry-pick origin/feature-branch~6
git cherry-pick origin/feature-branch~5
git cherry-pick origin/feature-branch~4
git cherry-pick origin/feature-branch~3
git cherry-pick origin/feature-branch~2
git cherry-pick origin/feature-branch~1
git cherry-pick origin/feature-branch~0

There has to be a less manual way. I can find the commit before the first commit on the branch with this command:

git merge-base origin/HEAD origin/feature-branch

Solution

  • The command you are looking for for the shown commit sequence is (assuming that none of the commits is a merge commit)

    git cherry-pick origin/feature-branch~10..origin/feature-branch
    

    But you ask for "cherry-picking every commit on a branch since merge-base origin/HEAD". I will assume you mean the "merge base of that branch and the current HEAD". Then the command would be

    git cherry-pick HEAD..origin/feature-branch