3

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

melder
  • 463
  • 2
  • 5
  • 9
  • When you say "squash" do you mean `rebase --squash` ? – willoller Oct 19 '12 at 21:17
  • I tried with to squash with interactive rebase and alternatively by this method: http://stackoverflow.com/questions/495345/git-removing-selected-commit-log-entries-for-a-repository (second answer). Both yielded the same result, i.e. the need to rebase each branch separately. – melder Oct 22 '12 at 19:04
  • Yes. No matter how you do it, you will have to do each branch separately. This is because each branch keeps its own history, and is unaffected by changes in other branches. – willoller Oct 22 '12 at 23:04

1 Answers1

3

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.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • Then, I think you will get what you want if you rebase your branches back on to `master`. – willoller Oct 19 '12 at 20:56
  • @willoller: Not quite, what you would get from a simple rebase is (for branch one) `A-C'-D'-B'-E'-F'`, and B wouldn't go away. – Greg Hewgill Oct 19 '12 at 21:10
  • No I think `B` goes away in this case, since `C'` will contain `B` (since he squashed it, not removed it) making the history `A-C'-E'-F'` – willoller Oct 19 '12 at 21:12
  • 1
    Oh, I see what you mean. It's unclear in the original question whether "want to squash commit B" actually means "combine B with C" (or maybe with A?), or "remove commit B entirely". I was assuming the latter, but your interpretation could be equally valid. – Greg Hewgill Oct 19 '12 at 21:16