Reputation: 677
git rebase is awesome, only problem is I want something slightly different. Let's say I have branchA and master. And say I have 3 commits made to branchA that is not within master.
master: 0 -> 1 -> 2
branchA: 0 -> 1 -> 2 -> 3 -> 4 -> 5
And then let's say I make a commit to master: 0 -> 1 -> 2 -> 6
Now when I rebase, branchA becomes: 0 -> 1 -> 2 -> 6 -> 4 -> 5
However, I want to do something slightly different involving a third branch. Let's call that branchB
branchB: 0 -> 1
And pretend I didn't rebase branchA, so it still looks like: 0 -> 1 -> 2 -> 3 -> 4 -> 5
I'm basically searching for a command or set of commands that will allow me to take master/branchA into account to determine that 0 -> 1 -> 2 are common commits and then based on that rebase onto branchB.
branchB should look like this once complete: 0 -> 1 -> 3 -> 4 -> 5
Because even though commit 2 was in both master and branchA, commit 1 is the closest parent that exist in branchB.
Is such a thing possible in git?
Upvotes: 3
Views: 1207
Reputation: 2989
If there are only few commits to deal with and you don't need automatic solution, you can use cherry-pick. Simply perform git cherry-pick commit
when on target branch to copy commits from another branch to your current branch.
Another way is to use git rebase -i
. Git will give you list of commits to be rebased, and lets you edit the list so you can adjust what is to be rebased and how.
Both ways are more or less manual, but they may be useful for one-time fixes. If you need automated solution for this, you are likely doing something wrong.
Upvotes: 2
Reputation: 1329092
I'm basically searching for a command or set of commands that will allow me to take
master/branchA
into account to determine that0 -> 1 -> 2
are common commits and then based on that rebase ontobranchB
.
See git merge-base
:
git rebase --onto B $(git merge-base master A) A
A git merge-base master A
would return 2
.
A git rebase --onto B 2 A
would replay onto B
all commits after 2 up to HEAD of A
.
Upvotes: 2