Draft Revert
Perform intelligent git revert that understands Draft's logical units of work.
Red Flags - STOP if you're:
- •Reverting without showing preview first
- •Skipping user confirmation
- •Not checking for uncommitted changes first
- •Reverting more than requested
- •Not updating Draft state after git revert
- •Assuming you know which commits to revert without checking
Preview and confirm before any destructive action.
Step 1: Analyze What to Revert
Ask user what level to revert:
- •Task - Revert a single task's commits
- •Phase - Revert all commits in a phase
- •Track - Revert entire track's commits
If user specifies by name/description, find the matching commits.
Step 2: Find Related Commits
Primary method: Read plan.md — every completed task has its commit SHA recorded inline. Use these SHAs directly.
Fallback method (if SHAs missing): Search git log by track ID pattern:
For Draft-managed work, commits follow pattern:
- •
feat(<track_id>): <description> - •
fix(<track_id>): <description> - •
test(<track_id>): <description> - •
refactor(<track_id>): <description>
# Find commits for a track git log --oneline --grep="<track_id>" # Find commits in date range (for phase) git log --oneline --since="<phase_start>" --until="<phase_end>" --grep="<track_id>"
Cross-reference: Verify SHAs from plan.md match the git log results. If mismatched, prefer git log as source of truth.
Step 3: Preview Revert
Show user what will be reverted:
═══════════════════════════════════════════════════════════
REVERT PREVIEW
═══════════════════════════════════════════════════════════
Reverting: [Task/Phase/Track] "[name]"
Commits to revert (newest first):
abc1234 feat(add-auth): Add JWT validation
def5678 feat(add-auth): Create auth middleware
ghi9012 test(add-auth): Add auth middleware tests
Files affected:
src/auth/middleware.ts
src/auth/jwt.ts
tests/auth/middleware.test.ts
Plan.md changes:
Task 2.1: [x] (abc1234) → [ ]
Task 2.2: [x] (def5678) → [ ]
═══════════════════════════════════════════════════════════
Proceed with revert? (yes/no)
Step 4: Execute Revert
If confirmed:
# Revert each commit in reverse order (newest first) git revert --no-commit <commit1> git revert --no-commit <commit2> # ... continue for all commits # Create single revert commit git commit -m "revert(<track_id>): Revert [task/phase description]"
Step 5: Update Draft State
- •
Update
plan.md:- •Change reverted tasks from
[x]to[ ] - •Remove the commit SHA from the reverted task line
- •Add revert note
- •Change reverted tasks from
- •
Update
metadata.json:- •Decrement tasks.completed
- •Decrement phases.completed if applicable
- •Update timestamp
- •
Update
draft/tracks.mdif track status changed
Step 6: Confirm
Revert complete Reverted: - [list of tasks/commits] Updated: - draft/tracks/<track_id>/plan.md - draft/tracks/<track_id>/metadata.json Git status: - Created revert commit: [sha] The reverted tasks are now available to re-implement. Run /draft:implement to continue.
Abort Handling
If user says no to preview:
Revert cancelled. No changes made.
If git revert has conflicts:
Revert conflict detected in: [files] Options: 1. Resolve conflicts manually, then run: git revert --continue 2. Abort revert: git revert --abort Draft state NOT updated (pending revert completion).