jota
jota

Reputation: 33

How to inject a commit between some two arbitrary commits in the past when there is multiple branch above?

The question is an extension of this one: How to inject a commit between some two arbitrary commits in the past?

Suppose I have the following commit history on my local-only branch:

A -- B -- C -- D  
            \- E

How do I insert a new commit between A and B and keep both D and E above C?

Upvotes: 1

Views: 1065

Answers (2)

Aurora Wang
Aurora Wang

Reputation: 1940

You can do an interactive rebase on your first branch to inject your commit and then do a rebase onto to apply this changes to your other branch.

Assuming you have:

A -- B -- C -- D  
           \-- E

After injecting your commit into your first branch (following the How to inject a commit between some two arbitrary commits in the past) you would have something like:

A -- A2 -- B' -- C' -- D'
 \-- B  -- C  -- E

Than you can do a rebase --onto from your another branch, to apply the changes it:

git rebase --onto C' E branch2

So you final result would be:

A -- A2 -- B' -- C' -- D'
                   \-- E'

Upvotes: 1

tmaj
tmaj

Reputation: 35075

Stop the madness :) and just add the commit to D and then either merge or cherry-pick it to E

A -- B -- C -- D -- X 
           \-- E -- X   

Upvotes: 0

Related Questions