Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

append branch commits with git

Tags:

git

git-rebase

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?

like image 790
Tim Kuipers Avatar asked Aug 27 '26 23:08

Tim Kuipers


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".

like image 107
Romain Valeri Avatar answered Aug 30 '26 19:08

Romain Valeri


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

like image 42
Ashok Arora Avatar answered Aug 30 '26 18:08

Ashok Arora



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!