4 ms·
Oh, I actually messed it up. Which in hindsight I don't know why because it's really much simpler than what I started with... but then I usually do it with more
by glandium 5y ago
Oh, I actually messed it up. Which in hindsight I don't know why because it's really much simpler than what I started with... but then I usually do it with more intermediate steps, and on an actual command line, not on a mobile phone...
Anyways:
You start with:
original-state
A
final-state
B
intermediate-state
You want
original-state
X
intermediate-state
Y
final-state
What you just need to do is:
git revert HEAD
Which gives you:
original-state
A
final-state
B
intermediate-state
revert (C)
final-state
Then X = A + B and Y = C, so with one rebase -i:
pick A
squash B
reword C
No conflicts. The important thing is that with appropriate reverts and reapplication of commits, you can make your history contain the states you want in the order you want, even if in between you have repeated states in the wrong order. Then you squash things so that you only keep the states you wanted in the first place.
Edit: but yes, you can achieve the same outcome with read-tree or checkout.
Edit2: come to think or it, you can probably do what you want with a couple git replace --graft and a noop filter-branch.