Help users undo mistakes and recover from errors in jj. Use when the user explicitly mentions 'jj undo', 'undo operation', or 'restore operation'. Covers quick undo, multiple undo scenarios, and redo workflows.
Limited to specific tools
Additional assets for this skill
This skill is limited to using the following tools:
Everything is undoable in jj. Every operation is recorded and can be reversed. There's no need to fear making mistakes.
Key insight: Jj auto-snapshots the working copy before every operation, so you can always go back.
jj undo - Reverse the Last OperationWhen to use: You just ran a command and immediately realized it was wrong.
What it does: Reverses the most recent operation, restoring the repository to its previous state.
Examples:
# Accidentally squashed the wrong commits
jj squash
jj undo # Reverses the squash
# Described a commit with the wrong message
jj describe -m "wrong message"
jj undo # Restores previous description
# Split commits incorrectly
/jj:split test
jj undo # Reverses the split
Important: jj undo affects the repository state, but working copy files update automatically to match.
You can run jj undo multiple times to step backwards through operations:
jj undo # Undo most recent operation
jj undo # Undo the one before that
jj undo # Keep going back
Workflow:
jj op log to see what operations you want to undojj undo once for each operation you want to reversejj status to verify the resultTip: Each jj undo is itself an operation, so you can undo an undo (see Redo section).
If you undo too many operations, you can "redo" by looking at the operation log:
Method 1: Undo the undo
jj undo # Undoes the last undo operation
Method 2: Restore to specific operation
jj op log # Find the operation ID you want
jj op restore <op-id> # Jump to that operation
Example:
jj squash # Operation A
jj undo # Operation B (undoes A)
jj undo # Operation C (undoes B, effectively redoing A)
jj undo vs jj op restore vs jj abandonUse jj undo when:
Use jj op restore <id> when:
Use jj abandon when:
Key difference: jj undo and jj op restore affect operations (what commands you ran), while jj abandon affects commits (what changes exist).
jj describe -m "typo in mesage"
jj undo
jj describe -m "correct message"
jj squash # Oops, wrong parent
jj undo
# Now squash correctly
/jj:split test # Split wasn't quite right
jj undo
/jj:split docs # Try different pattern
jj new # Oops, wasn't ready for new commit
jj undo
# Continue working in current commit
jj undo # Undo most recent
jj undo # Undo the one before
jj undo # Keep going until clean state
# Or use jj op log to find target and jj op restore
Does affect:
Does NOT affect:
Important: Even if you undo operations, the changes still exist in the operation log. You can always:
jj log --at-op=<old-op-id>jj op restorejj op logBottom line: In jj, you can't accidentally lose work. The operation log is your safety net.
Immediately suggest jj undo when:
Suggest exploring operation log when:
Proactive help:
/jj:commit/jj:commit # Claude generates commit message
# If message isn't quite right:
jj undo # Undo the description
/jj:commit # Try again with different context
jj new # Start new commit
# Realize you're not done with previous commit yet:
jj undo # Go back to previous commit
# Continue working
/jj:commit # Replace "plan:" with implementation
# Realize plan needs more work:
jj undo # Restore "plan:" description
# Continue implementing
Most common commands:
jj undo - Reverse last operation (use multiple times to go back further)jj op log - See what operations can be undonejj status - Verify state after undojj log - See commit history after undoRemember: Everything is recorded, everything is undoable, you can't lose work.