commit
npx machina-cli add skill PaulRBerg/agent-skills/commit --openclawGit Commit
Overview
Create atomic commits by staging the right files, analyzing the staged diff, composing a conventional commit message, and optionally pushing.
Workflow
0) Pre-flight checks
- Verify inside a git worktree:
git rev-parse --is-inside-work-tree - Verify not detached:
git symbolic-ref HEAD - Verify not in rebase/merge/cherry-pick state: check for
.git/rebase-merge,.git/MERGE_HEAD,.git/CHERRY_PICK_HEAD - If any check fails, stop with a clear error and suggested fix.
1) Collect context
- Current branch:
git branch --show-current - Git status:
git status --short --branch - Initial staged diff:
git diff --cached - Arguments:
$ARGUMENTS
Note: The staged diff may become stale after staging changes; re-read git diff --cached after STEP 2.
2) Handle staging
- If
--all:- If no changes at all: error "No changes to commit"
- If unstaged changes exist:
git add -A - If already staged: proceed
- Log staged files with status (A/M/D)
- Otherwise (atomic commits):
- Session-modified files = files edited in this session
- Currently staged files:
git diff --cached --name-only - For staged files NOT in session-modified set:
git restore --staged <file> - For session-modified files with changes:
git add <file> - Log staged files with status (A/M/D)
- If none: error "No files modified in this session"
- Unrelated changes: session-modified files may contain pre-existing uncommitted changes (hunks not from this session). Include the entire file—partial staging is impractical. Never revert, discard, or
git checkoutunrelated changes. - Re-read staged diff:
git diff --cached
3) Parse arguments
- Flags:
--allcommit all changes--deepdeep analysis, breaking changes, concise body--pushpush after commit
- Value arguments:
- Type keyword (any conventional type) overrides inferred type
- Quoted text overrides inferred description
- Precedence:
- Explicit type keyword in arguments
- Heuristic inference from diff
- Quoted text in arguments
- Heuristic inference from diff
4) Analyze changes
- Default:
- Read the staged diff
- Ignore unrelated hunks (pre-existing changes not from this session) when determining type, scope, and description. If unrelated changes are in the same file as session changes, they are included in the commit scope but should not influence the commit message.
- Determine change type from behavior:
- New functionality ->
feat - Bug fix or error handling ->
fix - Code reorganization without behavior change ->
refactor - Documentation changes ->
docs - Test additions/changes ->
test - Build system (webpack, vite, esbuild configs) ->
build - CI/CD pipelines (.github/workflows, .gitlab-ci) ->
ci - Dependencies ->
chore(deps) - Formatting/whitespace only ->
style - Performance improvements ->
perf - Reverting previous commit ->
revert - Other maintenance ->
chore - AI config (CLAUDE.md, AGENTS.md, .claude/, .gemini/, .codex/) ->
ai
- New functionality ->
- Infer scope only when path makes it obvious (lowercase)
- Extract a specific description of what changed (not just which files)
- If
--deep:- Deep semantic analysis; detect breaking changes
- Infer scope from code structure even when path isn't clear
- Check for GitHub issues in the chat transcript
- Keep output concise
Conventional types: feat, fix, docs, style, refactor, test, chore, build, ci, perf, revert, ai
5) Compose message
- Subject line (<= 50 chars):
type(scope): descriptionortype: description - Imperative mood ("add" not "added"), lowercase, no period
- Describe what the change does, not which files changed
- Default mode:
- Subject line required
- Body: hyphenated lines for distinct changes
- Skip body for trivial changes
- If
--deep:- Body: 2-3 hyphenated lines max, focus on WHY
- Breaking change:
BREAKING CHANGE:+ one-line migration note - GitHub issues:
Closes #123
6) Commit
- Use
git commit -m "subject"(add-m "body"only if body is non-empty) - Output: commit hash + subject + file count summary
- If failed: show error + suggest fix
7) Push (if --push)
- If upstream exists:
git push - If no upstream:
git push -u origin HEAD - If failed: show error + suggest fix (pull/rebase first, set upstream, check auth)
Examples
Trivial changes (subject only):
fix: correct typo in error message
style: format config file
chore(deps): bump lodash to 4.17.21
Default (subject + brief body):
feat(auth): add oauth2 login support
- Add Google and GitHub OAuth providers
- Integrate alongside existing password auth
Deep mode (concise, focused on WHY):
feat(webhooks): add retry mechanism for failed deliveries
- Prevent data loss when downstream services are temporarily unavailable
Source
git clone https://github.com/PaulRBerg/agent-skills/blob/main/skills/commit/SKILL.mdView on GitHub Overview
Create atomic commits by staging the right files, analyzing the staged diff, and composing a conventional-commit message. It supports optional deep analysis and pushing after commit using flags like --all, --deep, and --push.
How This Skill Works
The workflow starts with pre-flight checks to ensure a clean work tree. It then collects context (current branch, status, and staged diff) and applies staging rules based on --all or session-based changes. It parses arguments, optionally performs deep analysis to detect breaking changes, infers a conventional-commit type and scope, and can push after committing if requested.
When to Use It
- Commit all changes in the working tree with --all
- Create an atomic commit for only session-modified files, leaving unrelated changes untouched
- Run deep analysis (--deep) to detect breaking changes and craft a precise body
- Push the commit immediately after committing using --push
- Generate a conventional-commit message (feat, fix, docs, etc.) based on the changes
Quick Start
- Step 1: Run pre-flight checks to ensure a clean work tree
- Step 2: Stage changes using --all or per-session atomic staging rules
- Step 3: Commit with a conventional message and optionally push with --push
Best Practices
- Keep each commit atomic and focused on a single logical change
- Use conventional-commit types (feat, fix, docs, style, refactor, test, chore, build, ci, ai)
- Run pre-flight checks to ensure a clean, non-detached work tree before staging
- Review the staged diff to verify session scope and avoid including unrelated changes
- If in doubt, use --deep to surface potential breaking changes and document them in the body
Example Use Cases
- Add a new user authentication feature and push: feat(auth): add login flow
- Fix off-by-one bug in pagination and push: fix(pagination): correct index calculation
- Update contributing guidelines in docs: docs(contributing): update workflow
- Refactor module organization without changing behavior: refactor(core): reorganize package layout
- Update CI workflow to adjust cache strategy: ci(workflows): tweak caching