I have a branch like this:
A---B---B1---B2---D---E---E1---E2---G---H
\ / \ /
C1---C2---’ F1---F2---’
I want to rewrite it and make it like this:
A---B---B1---B2---D---E---E1---E2---G---H
That means, squashing all merges.
The branch is very long. How can this be done automatically?
Edit
This is not a history linearization. I want to squash all merges, like D and G.
This should do the trick. Since we are cherry picking the commit message, author, and author date will be the same as the original commits, including the merges.
Alternatively, you can get the commit message and authorship information from the last commit to the branch before the merge, i.e., the merge's second parent, by adding the following line to the first condition:
These commands can easily converted to a script if you do this often.
Checkout base commit (in detached state):
Cherry pick all commits:
Force old branch and checkout: