I’ve done this before by creating a clone and doing the rebase in the clone, but I suspect I could do it safely on a separate branch.
I have a feature branch feat-x with about 25 commits on it. I’d like to (safely) squash several of these together.
(I say “safely” because the first couple of times I squashed I didn’t get it right — but was working in a clone so just threw it away until I figured out the right incantation.)
What sequence of commands will give me feat-x-exp that is a copy of feat-x so I can experiment with squashing without disturbing feat-x?
I think you want to just do:
This checks out a copy of
feat-xthat you can experiment with. Once you’ve moved off thefeat-xbranch, you rebase commands won’t affect the original branch (so long as you avoid the two argument form that’s a shortcut for checking out before a rebase).If you mess up, you can go back to the state of the original branch with:
If your experiment is successful, you can move
feat-xto matchfeat-x-expand remove the experimental branch: