append branch commits with git

Viewed 84

I would like to append the commits of another branch to my current branch:

      A---B---C feat_A*
     /
o---o---o---o master
     \
      D---E---F feat_B


      A---B---C---D'--E'--F' feat_A*
     /
o---o---o---o master
     \
      D---E---F feat_B

However, doing a git rebase feat_B results in D---E---F---A'--B'--C'.

Another option would be to do

git checkout feat_B
git rebase feat_A

which results in the correct order A---B---C---D'--E'--F' but then these commits are in feat_B instead of feat_A.

How can I get git-rebase to append the commits of another branch onto the current one?

2 Answers

The operation could be easy without rebase, just cherry-pick the range you need :

git checkout feat_A
git cherry-pick ..feat_B

where ..feat_B is an implicit HEAD..feat_B, meaning "every commit from feat_B which is not already reachable from HEAD".

The git cherry-pick <commit> command allows you to take a single commit (from whatever branch) and, essentially, rebase it in your working branch.

Related