Reimplement current branch with clean, narrative-quality commit history
Resets current branch to main and recreates commits with clean, narrative-quality history.
/plugin marketplace add barnabasJ/claude/plugin install essentials@essentials-marketplaceReimplements the current branch with a clean, reviewer-friendly commit history. Creates a backup of the original branch, then rewrites commits as a logical narrative suitable for code review.
mainmainRun validation checks:
git status # No uncommitted changes
git diff main --stat # Confirm changes exist
git merge-base --is-ancestor main HEAD # Up to date with main
🚨 Stop if:
# Save current branch name
BRANCH=$(git branch --show-current)
# Create backup
git branch ${BRANCH}-backup
Study all changes between current branch and main:
git diff main --stat # Files changed
git diff main # Full diff
git log main..HEAD --oneline # Existing commits
Goal: Form a complete understanding of the final intended state.
Break the implementation into logical stages:
Each commit should:
Write the plan before executing.
# Reset to main, keeping changes in working directory
git reset main
Then recreate commits according to your plan:
git add <relevant-files>
git commit -m "$(cat <<'EOF'
type(scope): brief description
Explanation of what this step accomplishes and why.
EOF
)"
Repeat for each planned commit.
Confirm final state matches the backup:
git diff ${BRANCH}-backup
🚨 This must show no differences. If it does, investigate and fix.
Show the new commit history:
git log main..HEAD --oneline
Inform user of:
🚨 Never:
--force on shared branches🚨 Always:
--no-verify sparingly (only for known issues)type(scope): brief description (≤50 chars)
Longer explanation of what this commit does and why.
Focus on the narrative - what problem does this solve?
What decision was made and why?
Good narrative commits:
feat(plugin): add plugin manifest structure
Create .claude-plugin/plugin.json with required metadata.
This establishes the plugin identity for Claude Code's
plugin system.
refactor(commands): standardize frontmatter format
Ensure all command files have description field in
frontmatter as required by plugin specification.
Input: /rewrite-history
Process:
1. Validate: git status clean, changes exist vs main
2. Backup: git branch feature/auth-backup
3. Analyze: 5 files changed, 3 original commits
4. Plan storyline:
- feat: add user model
- feat: implement auth service
- feat: add login endpoint
- test: add auth test suite
- docs: update API documentation
5. Reset: git reset main
6. Reimplement: Create 5 clean commits
7. Verify: git diff feature/auth-backup (empty)
8. Report: "Created 5 commits, backup at feature/auth-backup"