Split Commit
Split a commit that mixes unrelated changes (e.g., docstrings + features) into separate commits.
Usage
- •
/split-commit- Split the most recent commit - •
/split-commit <commit-hash>- Split a specific commit
Instructions
- •
Identify the commit to split:
- •If
$ARGUMENTSis empty, useHEAD - •Otherwise, use the provided commit hash
- •If
- •
Show the commit contents:
bashgit show <commit> --stat git show <commit>
Ask the user: "How would you like to split this commit? Describe the two (or more) groups of changes."
- •
Save original files before resetting:
bash# For each file in the commit git show <commit>:<filepath> > /tmp/<filename>_original
- •
Reset to parent commit:
bashgit reset --hard <commit>^
- •
Apply first group of changes:
- •Using the saved files in
/tmp/as reference, apply only the first group - •Ask user for commit message
bashgit add <files> git commit -m "<message> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>"
- •Using the saved files in
- •
Apply remaining changes:
- •Restore full versions from
/tmp/originals - •Ask user for commit message
bashgit add <files> git commit -m "<message> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>"
- •Restore full versions from
- •
Verify and push:
bashgit log --oneline -3
Ask user: "Ready to force push these changes?"
bashgit push origin <branch> --force-with-lease
Important Notes
- •This rewrites history - only use on commits not yet merged
- •Always save files to
/tmp/BEFORE resetting - •The original commit is replaced by multiple new commits