melder
melder

Reputation: 463

How do I get git branch history to match master after a squash rebase?

Let's say I have the following tree structure:

A-B-C-D
    |\E-F (branch one)
     \G-H (branch two)

Master history: A-B-C-D
Branch one history: A-B-C-E-F
Branch two history: A-B-C-G-H

I want to squash commit B, so the respective histories should look like so:

A-C-D
A-C-E-F
A-C-G-H

I find out that, after I squash master, when I checkout branch one or two they still show the old history when I run git log. Does git copy the trees when branching? Do I need to rebase each branch individually?

Thanks

Upvotes: 3

Views: 193

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 992947

Yes, you need to rebase each branch individually. After removing commit B, you get

Master history: A-C'-D'
Branch one history: A-B-C-E-F
Branch two history: A-B-C-G-H

where C' and D' are like C and D except with B removed from the history. Branches one and two are unaffected by the master rebase. Another view of the result would be:

A-C'-D'
|\B-C-E-F (branch one)
 \B-C-G-H (branch two)

where A, not C, is now the closest common ancestor of all your branches.

Upvotes: 3

Related Questions