| name | split-commit |
| description | Split a commit with mixed changes into separate commits |
Split Commit
Keywords: git, commit split, atomic commits, rewrite history, force-with-lease, two-group split, bisectable, git reset, interactive patch, git add -p
Split a commit that mixes unrelated changes (e.g., docstrings + features) into separate commits.
Usage
/git:split-commit - Split the most recent commit
/git:split-commit <commit-hash> - Split a specific commit
Instructions
-
Identify the commit to split:
- If
$ARGUMENTS is empty, use HEAD
- Otherwise, use the provided commit hash
-
Show the commit contents:
git show <commit> --stat
git show <commit>
Output this prompt as plain text and stop (do NOT use AskUserQuestion — this is free-text input): "How would you like to split this commit? Describe the two (or more) groups of changes."
-
Save original files before resetting:
mkdir -p tmp/claude-artifacts/split-commit
git show <commit>:<filepath> > tmp/claude-artifacts/split-commit/<filename>_original
-
Reset to parent commit:
git reset --hard <commit>^
-
Apply first group of changes:
- Using the saved files in
tmp/claude-artifacts/split-commit/ as reference, apply only the first group
- Ask the operator for commit message
git add <files>
git commit -m "<message>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>"
-
Apply remaining changes:
- Restore full versions from
tmp/claude-artifacts/split-commit/ originals
- Ask the operator for commit message
git add <files>
git commit -m "<message>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>"
-
Verify and push:
git log --oneline -3
Ask the operator: "Ready to force push these changes?"
git push origin <branch> --force-with-lease
Important Notes
- This rewrites history - only use on commits not yet merged
- Always save files to
tmp/claude-artifacts/split-commit/ BEFORE resetting
- The original commit is replaced by multiple new commits
- This workflow assumes the two groups of changes are in separate files. If both groups modify the same file, use
git add -p (interactive patch mode) after step 4 to selectively stage each group instead of restoring from tmp/claude-artifacts/split-commit/