Smart Commit — Intelligent Git Commit Assistant
Version: 1.1.0 | Author: Shadows Company | License: MIT
WHEN TO TRIGGER
- - User says "commit", "smart commit", "save my changes", or "push"
- After completing a coding task when changes need to be committed
- User asks to review and commit staged changes
WHEN NOT TO TRIGGER
- - User explicitly says "don't commit" or "no commit"
- No changes exist in the working tree (
git status shows clean) - User is just browsing or reading code
PREREQUISITES
This skill requires only git on PATH. All commands are standard git operations that read repository state and create commits. No network access, no external APIs, no additional toolchains required.
PROCESS
Phase 1 — Reconnaissance
Run these commands to understand the current state:
CODEBLOCK0
Analyze:
- 1. What files changed (staged vs unstaged)
- The nature of changes (new feature, bugfix, refactor, docs, test, chore)
- Recent commit style to match existing conventions
Phase 2 — Security Scan (MANDATORY)
Before ANY commit, scan staged changes for leaked secrets:
CODEBLOCK1
If secrets detected: STOP immediately. Warn the user with the exact file:line. Do NOT proceed with the commit.
Check for files that should never be committed:
CODEBLOCK2
Blocked file patterns: .env, .env.*, *.pem, *.key, *.p12, *credentials*, *secret*, node_modules/, __pycache__/, INLINECODE11
Limitations: This grep-based scan catches common patterns but may produce false positives (e.g., test fixtures with "password" in variable names) or miss obfuscated secrets. For high-security projects, complement with gitleaks or trufflehog.
Phase 3 — Staging Strategy
- - NEVER use
git add . or git add -A — these can accidentally include sensitive files - Stage files individually by name: INLINECODE14
- Group related files logically in the same commit
- If unrelated changes exist, suggest splitting into multiple atomic commits
Phase 4 — Commit Message Generation
Follow Conventional Commits specification (conventionalcommits.org):
CODEBLOCK3
Types: feat, fix, refactor, docs, test, chore, perf, style, build, INLINECODE24
Rules:
- - Subject line: max 72 characters, imperative mood ("add" not "added")
- Focus on WHY, not WHAT (the diff shows WHAT)
- Include scope when changes are localized to a module
- Use HEREDOC for multi-line messages to preserve formatting:
CODEBLOCK4
Phase 5 — Verification
After commit, verify success:
CODEBLOCK5
Confirm: commit SHA visible, working tree status as expected.
SECURITY CONSIDERATIONS
- 1. Read-only analysis: Phases 1-2 only read git state (status, diff, log). No files are modified, no network calls are made.
- 2. Secret detection output: Phase 2 may display matched secret-like patterns in terminal output. Run in a secure terminal where output is not forwarded to shared logging systems.
- 3. Write operations: Phase 3 (
git add) and Phase 4 (git commit) modify git state. These are local operations — no data is pushed to any remote unless the user explicitly requests git push afterward.
- 4. No persistence: This skill does not store credentials, modify config files, or install packages. Each invocation is stateless.
- 5. No network access: The entire workflow is local.
git push is never executed unless the user explicitly requests it as a separate step.
OUTPUT FORMAT
CODEBLOCK6
RULES (by priority)
- 1. Security first — NEVER commit secrets, tokens, API keys
- Specific staging — NEVER
git add . — always name files explicitly - Conventional format —
type(scope): message always - Meaningful messages — explain intent, not just what changed
- No force push — NEVER
git push --force on main/master - No amend — create NEW commits unless explicitly asked to amend
- No skip hooks — NEVER use INLINECODE32
- Atomic commits — one logical change per commit
Published by Shadows Company — "We work in the shadows to serve the Light."
智能提交 — 智能Git提交助手
版本: 1.1.0 | 作者: Shadows Company | 许可证: MIT
触发时机
- - 用户说提交、智能提交、保存我的更改或推送
- 完成编码任务后需要提交更改时
- 用户要求审查并提交暂存的更改
不触发时机
- - 用户明确说不要提交或不提交
- 工作树中没有更改(git status 显示干净)
- 用户只是在浏览或阅读代码
前置条件
此技能仅需在 PATH 中包含 git。所有命令均为读取仓库状态和创建提交的标准 git 操作。无需网络访问、无需外部 API、无需额外工具链。
流程
第一阶段 — 侦察
运行以下命令了解当前状态:
bash
git status
git diff --cached --stat
git diff --stat
git log --oneline -5
分析:
- 1. 哪些文件发生了更改(已暂存 vs 未暂存)
- 更改的性质(新功能、错误修复、重构、文档、测试、杂项)
- 最近的提交风格以匹配现有惯例
第二阶段 — 安全扫描(必选)
在任何提交之前,扫描暂存的更改是否存在泄露的密钥:
bash
扫描暂存的差异以查找密钥模式
git diff --cached | grep -inE (api[
-]?key|secret|token|password|credential|private[-]?key)\s
[:=]\s[\][^\]{8,} || echo 通过:暂存更改中未检测到密钥
如果检测到密钥:立即停止。向用户警告确切的文件:行号。不要继续提交。
检查不应提交的文件:
bash
检查是否暂存了危险文件
git diff --cached --name-only | grep -iE \.(env|pem|key|p12|pfx)$|credentials|secret || echo 通过:未暂存敏感文件
被阻止的文件模式:.env、.env.、.pem、.key、.p12、credentials、secret、nodemodules/、pycache/、.DSStore
局限性:此基于 grep 的扫描可捕获常见模式,但可能产生误报(例如,变量名中包含password的测试夹具)或遗漏混淆的密钥。对于高安全性项目,请配合 gitleaks 或 trufflehog 使用。
第三阶段 — 暂存策略
- - 绝不使用 git add . 或 git add -A — 这些可能意外包含敏感文件
- 按名称逐个暂存文件:git add src/feature.ts tests/feature.test.ts
- 在同一个提交中逻辑地分组相关文件
- 如果存在不相关的更改,建议拆分为多个原子提交
第四阶段 — 提交消息生成
遵循约定式提交规范(conventionalcommits.org):
type(scope): 简洁描述
[可选正文,解释为什么,而不是什么]
Co-Authored-By: Claude
类型:feat、fix、refactor、docs、test、chore、perf、style、build、ci
规则:
- - 主题行:最多 72 个字符,祈使语气(使用添加而非已添加)
- 关注为什么,而不是什么(差异显示的是什么)
- 当更改局限于某个模块时包含范围
- 对于多行消息使用 HEREDOC 以保留格式:
bash
git commit -m $(cat <
type(scope): 主题行
解释动机的正文。
Co-Authored-By: Claude
EOF
)
第五阶段 — 验证
提交后,验证成功:
bash
git log --oneline -1
git status
确认:提交 SHA 可见,工作树状态符合预期。
安全考虑
- 1. 只读分析:第一至第二阶段仅读取 git 状态(状态、差异、日志)。不修改文件,不进行网络调用。
- 2. 密钥检测输出:第二阶段可能在终端输出中显示匹配的密钥模式。请在安全的终端中运行,确保输出不会转发到共享日志系统。
- 3. 写操作:第三阶段(git add)和第四阶段(git commit)会修改 git 状态。这些是本地操作——除非用户随后明确请求 git push,否则不会将数据推送到任何远程仓库。
- 4. 无持久化:此技能不存储凭据、不修改配置文件、不安装包。每次调用都是无状态的。
- 5. 无网络访问:整个工作流程在本地进行。除非用户明确请求作为单独步骤,否则绝不执行 git push。
输出格式
markdown
检测到的更改
- - [文件列表及更改类型:已添加/已修改/已删除]
安全扫描
- - 差异中的密钥:[通过 — 未检测到 / 失败 — 在文件:行号找到]
- 敏感文件:[通过 — 未暂存 / 失败 — 文件列表]
建议的提交
type(scope): 消息
要暂存的文件
提交后
- - SHA:[短哈希]
- 状态:[干净 / 剩余未暂存的更改]
规则(按优先级排序)
- 1. 安全第一 — 绝不提交密钥、令牌、API 密钥
- 指定暂存 — 绝不使用 git add . — 始终显式指定文件名
- 约定格式 — 始终使用 type(scope): 消息
- 有意义的消息 — 解释意图,而不仅仅是更改了什么
- 不强制推送 — 绝不在主分支上使用 git push --force
- 不修改 — 除非明确要求修改,否则创建新提交
- 不跳过钩子 — 绝不使用 --no-verify
- 原子提交 — 每个提交只包含一个逻辑更改
由 Shadows Company 发布 — 我们在暗处工作,以服务光明。