-3

I have the following situation:

branch A -- a1 -- a2 -- a3
      \    
       branch B -- b1 -- b2
                           \
                            branch C -- c1 -- c2

I want to git rebase branch C to branch A, but discard all changes that were made as part of branch B, so it looks like something like this

branch A -- a1 -- a2 -- a3 -- c -- c1 -- c2 (but without any changes made from B, b1, b2)

What is the cleanest approach to do this?

Aiyuni
  • 780
  • 5
  • 15
  • 1
    The graph is not clear. The branches should point to the last commit on that branch and the arrows should point to the parent commit. If the graph follows this convention then branch A is a merge commit; it merges commits `a1` and `b1` and the question does not make any sense. Also, the commit `c1` is not listed in the expected result. Is this the expected result? – axiac Aug 16 '22 at 20:12
  • @axiac I updated the graphs – Aiyuni Aug 16 '22 at 20:15
  • 1
    Have you read the [documentation of `git rebase`](https://git-scm.com/docs/git-rebase)? It contains both the answer to your question and some intelligible example commit graphs. – axiac Aug 16 '22 at 20:19

1 Answers1

0

Your diagram is meaningless (in part because you seem not to know what a branch is, in Git), but I assume you mean you'd like to go from this:

a1 -- a2 -- a3 (A)
  \    
   b1 -- b2 (B)
           \
            c1 -- c2 (C)

to this:

a1 -- a2 -- a3 (A)
 \           \
  \           c1' -- c2' (C)
   \
    b1 -- b2 (B)

To do so, you would say

git rebase --onto A B C
matt
  • 515,959
  • 87
  • 875
  • 1,141