undo-work
Safely undo work when an implementation attempt has gone wrong. Provides structured rollback with safeguards against accidental data loss.
Arguments: $ARGUMENTS
1. Assess Current State
git status
git log --oneline -10
git stash list
Determine the situation:
- Uncommitted changes only → Soft or hard reset options
- One or more commits on feature branch → Revert commits or reset branch
- Mid-story-cycle → Full story rollback
Present findings to the user before proceeding.
2. Confirm Scope with User
Show the user:
- Files that will be affected (list modified/added/deleted files)
- Commits that will be reverted (if any)
- Whether there's uncommitted work at risk
Ask the user to confirm one of these rollback levels:
| Level | What it does | When to use |
|---|---|---|
| Soft | Stash uncommitted changes (recoverable via git stash pop) |
"Let me save this aside and try a different approach" |
| Hard | Discard all uncommitted changes | "This attempt is wrong, start fresh from last commit" |
| Story | Reset branch to before the story's commits | "The whole story implementation needs to restart" |
3. Execute Rollback
Soft (stash)
git stash push -m "undo-work: <user-provided reason or auto-description>"
Report: "Changes stashed. Use git stash pop to recover if needed."
Hard (discard uncommitted)
git diff --stat # Show what will be lost — confirm with user
git stash push --include-untracked -m "undo-work: <user-provided reason>"
git stash drop # Discard the stash (changes intentionally discarded)
This captures both tracked changes AND untracked files into a stash, achieving a clean working directory. If the user changes their mind before the drop, git stash pop recovers everything.
Story (reset branch to before story commits)
- Check for story-cycle checkpoint tags first:
git tag -l 'story-checkpoint-*'
If a checkpoint tag exists, prefer it as the rollback target — it was set by story-cycle Phase 3.pre at the exact point before implementation began.
- If no checkpoint tag exists, identify the commit where the story started:
git log --oneline main..HEAD
Show the user exactly which commits will be removed (or that a checkpoint tag was found).
After confirmation:
If checkpoint tag exists:
git stash push --include-untracked -m "undo-work: story rollback backup"
git reset --soft <checkpoint-tag>
git restore .
git tag -d <checkpoint-tag>
If no checkpoint tag (fall back to commit-based):
git reset --soft <commit-before-story> # Keep changes staged (safest)
User wants a clean slate (not just unstaged)
git stash push --include-untracked -m "undo-work: story rollback backup"
git reset --soft <commit-before-story>
git restore .
4. Verify Clean State
git status
git log --oneline -5
Confirm the working directory is in the expected state.
5. Document (Optional)
The failed attempt has useful learnings
Suggest the user note what went wrong in the current session context so the next attempt avoids the same pitfalls. Do NOT auto-create documentation files.
Rules
- NEVER execute destructive git commands without showing the user exactly what will be affected and getting explicit confirmation
- NEVER force push after a reset — the rollback is local only
- Always prefer
git stash --include-untracked(recoverable) over destructive alternatives. Usegit restore .for discarding tracked file changes,git reset --softfor undoing commits while keeping changes staged - If on
mainbranch, REFUSE to reset — only feature/sprint branches - If there are commits that have already been pushed to remote, WARN the user that local reset won't affect the remote