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: Split the current `git` commit into multiple focused, self-contained, easy to review commits.4---56Split the current `git` commit into multiple focused, self-contained, easy to7review commits.89# Current commit1011```!12git show13```1415$ARGUMENTS1617# Principles1819- One concern per commit: e.g. bug fix, feature, refactor, or config change20- Each commit passes all checks: format, lint, typecheck, build, test21- Commit tests with the code they test22- Never mix refactors with behavioral changes23- Prefer thin vertical slices, one complete feature end-to-end, over horizontal24 layers25- Use every added API, abstraction, or stub within the same commit. Don't split26 so small that a commit introduces dead code2728# Workflow29301. Read the diff above. If the commit is already small and self-contained, tell31 the user and stop322. Identify logical groupings and order them from most foundational to most33 dependent. When a boundary is ambiguous, keep changes together343. Infer verification commands from project files (e.g. `package.json`,35 `Makefile`, CI config). If there are none, ask the user364. Present the plan as a numbered list:37 - Commit N: `<imperative-mood description>: <file or hunk list>`38 - One sentence justifying each split boundary39 - The verification commands you will run after each split40 - Ask for confirmation before proceeding415. Run `git reset HEAD~1` so all changes return to the working tree426. Stage and commit each group in order, running verification commands after43 each:44 ```sh45 git stash46 <verification commands>47 git stash pop48 ```497. After all splits, run `git log --oneline -<commit count>` and show the50 resulting stack5152# How to split5354## By file5556Stage specific files for the first commit, then commit:5758```sh59git add <files for first commit>60git commit -m "<first commit description>"61```6263## By hunk6465When a single file contains changes that belong in different commits:66671. Edit the file to contain only the changes for the first commit, removing the68 hunks that belong later692. Stage and commit it703. Re-edit the file to restore the removed hunks before the next commit