Split the current git commit into multiple focused, self-contained, easy to
review commits.
Current commit
git show
$ARGUMENTS
Principles
- One concern per commit: e.g. bug fix, feature, refactor, or config change
- Each commit passes all checks: format, lint, typecheck, build, test
- Commit tests with the code they test
- Never mix refactors with behavioral changes
- Prefer thin vertical slices, one complete feature end-to-end, over horizontal
layers
- Use every added API, abstraction, or stub within the same commit. Don't split
so small that a commit introduces dead code
Workflow
- Read the diff above. If the commit is already small and self-contained, tell
the user and stop
- Identify logical groupings and order them from most foundational to most
dependent. When a boundary is ambiguous, keep changes together
- Infer verification commands from project files (e.g.
package.json,
Makefile, CI config). If there are none, ask the user
- Present the plan as a numbered list:
- Commit N:
<imperative-mood description>: <file or hunk list>
- One sentence justifying each split boundary
- The verification commands you will run after each split
- Ask for confirmation before proceeding
- Run
git reset HEAD~1 so all changes return to the working tree
- Stage and commit each group in order, running verification commands after
each:
git stash
<verification commands>
git stash pop
- After all splits, run
git log --oneline -<commit count> and show the
resulting stack
How to split
By file
Stage specific files for the first commit, then commit:
git add <files for first commit>
git commit -m "<first commit description>"
By hunk
When a single file contains changes that belong in different commits:
- Edit the file to contain only the changes for the first commit, removing the
hunks that belong later
- Stage and commit it
- Re-edit the file to restore the removed hunks before the next commit
1---2name: git-split3description: |4 Split the current `git` commit into multiple focused, self-contained, easy to5 review commits.6argument-hint: '[extra guidance on how to split]'7allowed-tools:8 - Bash(git show *)9 - Bash(git log *)10 - Bash(git reset HEAD~1)11 - Bash(git add *)12 - Bash(git commit *)13 - Bash(git stash)14 - Bash(git stash pop)15---1617Split the current `git` commit into multiple focused, self-contained, easy to18review commits.1920# Current commit2122```!23git show24```2526$ARGUMENTS2728# Principles2930- One concern per commit: e.g. bug fix, feature, refactor, or config change31- Each commit passes all checks: format, lint, typecheck, build, test32- Commit tests with the code they test33- Never mix refactors with behavioral changes34- Prefer thin vertical slices, one complete feature end-to-end, over horizontal35 layers36- Use every added API, abstraction, or stub within the same commit. Don't split37 so small that a commit introduces dead code3839# Workflow40411. Read the diff above. If the commit is already small and self-contained, tell42 the user and stop432. Identify logical groupings and order them from most foundational to most44 dependent. When a boundary is ambiguous, keep changes together453. Infer verification commands from project files (e.g. `package.json`,46 `Makefile`, CI config). If there are none, ask the user474. Present the plan as a numbered list:48 - Commit N: `<imperative-mood description>: <file or hunk list>`49 - One sentence justifying each split boundary50 - The verification commands you will run after each split51 - Ask for confirmation before proceeding525. Run `git reset HEAD~1` so all changes return to the working tree536. Stage and commit each group in order, running verification commands after54 each:55 ```sh56 git stash57 <verification commands>58 git stash pop59 ```607. After all splits, run `git log --oneline -<commit count>` and show the61 resulting stack6263# How to split6465## By file6667Stage specific files for the first commit, then commit:6869```sh70git add <files for first commit>71git commit -m "<first commit description>"72```7374## By hunk7576When a single file contains changes that belong in different commits:77781. Edit the file to contain only the changes for the first commit, removing the79 hunks that belong later802. Stage and commit it813. Re-edit the file to restore the removed hunks before the next commit