We want to squash the v
commits in
v1
v2
v3
k1
k2
where the history v1-v2-v3 has complicated merges inside, and we want to retain k1
and k2
as separate commits.
The desired state is:
[ v1 v2 v3 ]
k1
k2
where [ ... ]
means "squashed into a single commit".
Initial state:
v1
v2
v3
k1
k2
Step 1: Squash everything.
[ v1 v2 v3 k1 k2 ]
Step 2: Revert (in reverse order) and cherry-pick (in desired order) the k
commits.
[ v1 v2 v3 k1 k2 ]
revert-k2
revert-k1
k1 (cherry-picked)
k2 (cherry-picked)
Step 3: Squash the revert-k1
commit into the previous.
[ v1 v2 v3 k1 k2 revert-k2 revert-k1 ]
k1
k2
This is equivalent to:
[ v1 v2 v3 k1 revert-k1 ]
k1
k2
This is equivalent to:
[ v1 v2 v3 ]
k1
k2