Ex post facto diff surgery
Sometimes you make a bunch of changes and then decide you want to split them up. The interactive change editor in jj
makes it (relatively) easy to slice up a big change into smaller revisions—even if those changes are jumbled in the same file.
Let's say all of my changes are in a revision named xyz
. I can spin off a new revision and immediately enter interactive squash mode like this:
jj new xyz; jj squash -f xyz -i
The first part (jj new xyz
) creates a new change from v
and puts sets it as the working copy (i.e. puts us "in" that new change). jj squash -f xyz -i
then starts an interactive squash (-i
) from v
(--from xyz
/-f xyz
) into the current change (you could write --to @
or -t @
, but squash
also does this implicitly if you don't specify a --to
).
You can navigate the editor with up and down arrow keys. Since everything is in one file, you can drill down to a line-by-line view by pressing f
(for fold/unfold), and toggle individual lines for squashing with space or enter. The lines you select get squashed as edits in the new change, and the rest stay as edits in the existing change.
After squashing, you can run jj desc -m "My message here"
to describe you change, then rinse and repeat.
(You could theoretically make a message before you squash by passing it to jj new
, but it's usually easier for me to do it after, because I don't know what part of the edit I'm going to split off until I'm perusing the diff.)