6

I have two branches in git with this shape.

* fffffff commit f
* ddddddd commit d
* bbbbbbb commit b
| * eeeeeee commit e
| * ccccccc commit c
| * aaaaaaa commit a
|/  
* 2222222 base revision 2
* 1111111 base revision 1

I want to rebase and reorder the commits like I would with rebase --interactive. However I want to interleave several of the commits and wind up with a shape like this.

* ffffff2 commit f
* eeeeee2 commit e
* dddddd2 commit d
* cccccc2 commit c
* bbbbbb2 commit b
* aaaaaaa commit a
* 2222222 base revision 2
* 1111111 base revision 1

Is there a way to do this rebase in one step? I tried to do it in two steps by rebasing commit b on top of commit e and then doing a second interactive rebase to sort all the commits. The problem is that I get merge conflicts (between commit b and commit e for example) that I would not see otherwise (by placing commit b after commit a) and it's not worth resolving the conflicts.

Craig P. Motlin
  • 26,452
  • 17
  • 99
  • 126

1 Answers1

8

Start with any one branch (either BranchWithF or BranchWithE) and issue the interactive rebase, for example

git checkout BranchWithF
git rebase -i HEAD~3

When the editor and the commit list pops up, add (read: type on your keyboard...) and interleave

pick aaaaaaa
pick ccccccc
pick eeeeeee

to the list as you see fit.

Afterwards, BranchWithF will have all 6 commits, and you can throw away BranchWithE (which still has its 3 commits).

user502515
  • 4,346
  • 24
  • 20
  • Wow, perfect! I never knew you could add lines during an interactive rebase. I had a similar question that you should get credit for here: http://stackoverflow.com/questions/3251011/can-i-rebase-and-squash-commits-at-the-same-time – Craig P. Motlin Dec 29 '10 at 15:39