Git Commit Guard
Treat every coding task as operating on a potentially valuable worktree.
Start Of Turn
- Run
git status --short --branchfirst. - If the repository is clean, continue to the requested work.
- If the repository is dirty, stop new development first.
- Inspect modified, deleted, and untracked files with
git diff --stat,git diff, and targeted file reads. - Summarize what changed by file and by intent before editing anything else.
- Infer the strongest reasonable validation from the repo itself. Prefer existing test, lint, type-check, compile, or build commands over ad hoc checks.
- Use the narrowest command that gives real signal for the dirty changes, then broaden if the change is cross-cutting.
- If validation fails, surface the blocker immediately. Fix it only when that is in scope and safe; otherwise do not create a normal commit.
- If validation passes and the dirty changes are intentional, create a detailed Chinese git commit before starting the next implementation step.
Dirty Worktree Handling
When git status is not clean, do all of the following before new development:
- Review whether the changes look coherent, risky, incomplete, or broken.
- Inspect tests related to the changed files when feasible.
- Call out uncertainty if unrelated edits may have been mixed together.
- Preserve the user's existing work. Do not discard, overwrite, or silently clean up unrelated changes.
During Work
- Keep unrelated changes in separate commits whenever practical.
- Do not mix pre-existing dirty changes with new feature work without reviewing both scopes.
- Before starting a new logical phase that depends on a clean base, commit the validated current state.
- Avoid destructive git commands unless the user explicitly asks for them.
Verification Standard
Before committing existing dirty changes, prefer this order:
- Targeted tests for touched modules or packages
- Fast lint, type-check, or compile commands relevant to touched files
- Broader project test commands if the repository is small or the change is cross-cutting
Before the final commit, run a broader validation pass whenever practical:
- Full or broader unit test coverage
- Lint
- Type check
- Build or compile
- Targeted smoke test for the implemented flow
If the full sweep is not feasible, state exactly what was run and what was not run.
End Of Turn
- Re-read the final diff before the last commit.
- If files changed during the turn, run the strongest reasonable final validation.
- If the requested development is finished, or the conversation is likely ending, prefer comprehensive validation over a narrow spot check.
- If validation passes, stage the final diff and create a detailed Chinese git commit before sending the final response.
- If no files changed, do not create an empty commit.
- Confirm
git statusis clean after the final commit. - If the repository is not a git repo, say that this skill is not applicable.
Commit Policy
- Write every commit message in Chinese.
- Use a concise subject line plus a detailed body.
- Explain what changed, why it changed, implementation details, verification status, and any known limitation or follow-up.
- If a commit preserves user changes before new work begins, say that explicitly so the history remains auditable.
- When drafting the message, read
references/commit-template.mdfor the preferred structure and examples.
Recommended type values:
featfixrefactortestdocschore
Response Behavior
- Mention early when the worktree is dirty and what you are reviewing.
- Tell the user what you verified before each commit.
- Surface failures immediately with the likely cause.
- After each commit, report the commit purpose clearly in Chinese.
- In the final response, include the validation that ran, the commit hash or hashes created during the turn, and any residual risk.