Mohan Mohan - 1 year ago 62
Git Question

Git: squashing material shared between branches

I have a git respository that looks a little like this:

C0 ---- C1 ---- ... ---- C12 ---- C14 (dev)
\---- C13 (abandoned)

'dev' is the main development branch, and 'abandoned' is an experiment that we may want to revisit at some point in the future.
I would like to squash
down into a single commit, to get something like this:

C0 ---- C1' ---- C14' (dev)
\---- C13' (abandoned)

I could use interactive rebase on dev to get

C0 ---- C1' ---- C14' (dev)

then check out
and cherry-pick
. But is there any easier way of doing this, that would also scale up to handle more complex diagrams with more branches and divergent commits (but some shared history to be squashed) without a lot of manual work?

Answer Source

You're on the right track. First, ignore C13 and just squash down to C0 - C1' - C14' with an interactive rebase. But then don't cherry-pick, but rebase C13onto C1'. git should detect that this is basically a no-op, and you will be done. So:

git rebase --onto C1_new C12 C13
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download