Home > Mobile >  git cherry-pick all missing commits between two branches from the same master
git cherry-pick all missing commits between two branches from the same master

Time:02-17

I have the following situation:

two branches were created from master at different times

    T0                T1
---- ----------------- ------> master
    |                 |
    |                 |
     ---- BranchA      ---- BranchB

Development occurred on BranchA after time T0

Some, but not all of those commits were merged in master after time T0, but before time T1

I would like to now cherry-pick all the commits in BranchA that do not exist in BranchB into BranchB

CodePudding user response:

Untested, but

git switch BranchB # Use git checkout BranchB if you prefer.
git cherry-pick ..BranchA

should work. Taken from the examples section of https://git-scm.com/docs/git-cherry-pick.

CodePudding user response:

Instead of cherry picking, rebase.

First, rebase branchA onto master.

This brings branchA up to date. No question of what parts of branchA are in master. No question whether they're compatible with master.

This will greatly simplify the process and give you an opportunity to resolve any conflicts between branchA and master without also involving branchB.

It's probably also a good idea to rebase branchB onto master just to make sure both branches are up to date and are working from a common base.

Then rebase branchB onto branchA. Or vice versa. Or cherry pick master..branchA (all the commits on branchA which are not in master) onto branchB.

  • Related