I think that my title is not clear enough, so I will describe the problem:
In my git project, I have 3 branches: master, b1, and b2. Here is the history tree:
A---B---C master
\
D---E---F b1
\
G---H---I b2
Suppose I want to rebase the b1 branch and edit the E commit. After rebasing, commits E and F will be replaced by new commits E' and F' which have different commit SHAs. Therefore, the history in b1 will be different from history in b2:
A---B---C master
\
D---E'---F' b1
A---B---C---D---E---F---G---H---I b2
So my question is: how to make sure that b2 follows b1 (automatically gets the same new commits as b1) after rebasing b1 so that their respective histories stay coherent.
After your first rebase, it's not this:
but rather this:
Here,
Eameans the amendedEcommit. And you want this, if I understand correctly:You can achieve this using an interactive rebase:
In the rebase edit you comment out the lines for commit E:
Responding to your comment, if you want to go all the way from the starting position (ABCDEFGHI) to the desired end positon:
In the editor:
When done, correct the
b1branch:You can also look at the other answers for inspiration. I'm not sure why you want to achieve all of this in a single command; you still have to amend commit E somewhere in the process. It saves you one interactive rebase to do it this way.