2

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?

Tim Kuipers
  • 1,705
  • 2
  • 16
  • 26
  • possible duplicate of [How to merge a specific commit in Git](https://stackoverflow.com/questions/881092/how-to-merge-a-specific-commit-in-git) – Ashok Arora May 18 '20 at 10:05

2 Answers2

1

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

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • I didn't know you could cherry-pick a range. Sadly there is not an interactive version of cherry-pick. I had to omit and edit some commits by hand. – Tim Kuipers May 18 '20 at 11:38
1

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

Ashok Arora
  • 531
  • 1
  • 6
  • 17