git
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Skill
Git Skill
Code is Mechanism, Prompt is Policy
代码是机制,提示词是策略
Architecture
架构说明
This skill uses decorator in files.
Commands are automatically exposed via MCP as .
@skill_commandscripts/*.pygit.command_name本Skill在文件中使用装饰器。命令会通过MCP自动暴露为格式。
scripts/*.py@skill_commandgit.command_nameAvailable Commands
可用命令
| Command | Description |
|---|---|
| Show working tree status |
| Stage all changes (with security scan) |
| Commit staged changes |
| Smart Commit workflow (stage → scan → approve → commit) |
| Push to remote |
| Show commit logs |
| 命令 | 描述 |
|---|---|
| 显示工作区状态 |
| 暂存所有变更(含安全扫描) |
| 提交已暂存的变更 |
| 智能提交流程(暂存 → 扫描 → 审批 → 提交) |
| 推送到远程仓库 |
| 显示提交日志 |
Smart Commit Workflow
智能提交流程
Use for secure, human-in-the-loop commits:
git.smart_commitpython
undefined使用实现安全的、需人工参与的提交流程:
git.smart_commitpython
undefinedStep 1: Start workflow
Step 1: 启动流程
git.smart_commit(action="start")
git.smart_commit(action="start")
Returns workflow_id and diff preview
返回workflow_id和差异预览
Step 2: After LLM analysis and user approval
Step 2: 经LLM分析和用户审批后
git.smart_commit(action="approve", workflow_id="xxx", message="feat: description")
**Flow:** `stage_and_scan` → `route_prepare` → `format_review` → `re_stage` → `interrupt` → `commit`git.smart_commit(action="approve", workflow_id="xxx", message="feat: description")
**流程步骤:** `stage_and_scan` → `route_prepare` → `format_review` → `re_stage` → `interrupt` → `commit`Staged Files Feature
暂存文件功能
Stage and Scan Workflow
暂存与扫描流程
The function provides automatic staging with security validation:
stage_and_scanStage All Files → Security Scan → Lefthook Pre-commit → Finalizestage_and_scan暂存所有文件 → 安全扫描 → Lefthook预提交检查 → 完成Key Features
核心特性
-
Automatic Stagingpython
stage_and_scan(project_root=".") # Returns: {staged_files, diff, security_issues, lefthook_error} -
Security Scanning
- Detects sensitive files (,
.env*,*.pem,*.key, etc.)*.secret - Automatically un-stages detected files
- Returns list of security issues
- Detects sensitive files (
-
Lefthook Integration
- Runs pre-commit hooks after staging
- Re-stages files modified by lefthook formatters
- Returns lefthook output for review
-
自动暂存python
stage_and_scan(project_root=".") # 返回: {staged_files, diff, security_issues, lefthook_error} -
安全扫描
- 检测敏感文件(,
.env*,*.pem,*.key等)*.secret - 自动取消检测到的敏感文件的暂存状态
- 返回安全问题列表
- 检测敏感文件(
-
Lefthook集成
- 暂存后运行预提交钩子
- 重新暂存由Lefthook格式化工具修改的文件
- 返回Lefthook输出结果供审核
Staged Files Commands
暂存文件相关命令
| Command | Description |
|---|---|
| Stage all changes with security scan |
| Show staged files and working tree status |
| Show staged diff |
| 命令 | 描述 |
|---|---|
| 暂存所有变更(含安全扫描) |
| 显示已暂存文件和工作区状态 |
| 显示已暂存内容的差异 |
Security Patterns Detected
检测到的安全文件模式
.env*, *.env*, *.pem, *.key, *.secret, *.credentials*
id_rsa*, id_ed25519*, *.priv
secrets.yml, secrets.yaml, credentials.yml.env*, *.env*, *.pem, *.key, *.secret, *.credentials*
id_rsa*, id_ed25519*, *.priv
secrets.yml, secrets.yaml, credentials.ymlUsage Guidelines
使用指南
Read Operations (Safe - Use Claude-native bash)
读取操作(安全操作 - 使用Claude原生bash)
bash
git status
git diff --cached
git diff
git log --onelinebash
git status
git diff --cached
git diff
git log --onelineWrite Operations (Use MCP Tools)
写入操作(使用MCP工具)
| Operation | Tool |
|---|---|
| Stage all | |
| Commit | |
| Push | |
| Smart Commit | |
| 操作 | 工具 |
|---|---|
| 暂存所有变更 | |
| 提交 | |
| 推送至远程 | |
| 智能提交 | |
Key Principle
核心原则
Read = Claude-native bash. Write = MCP tools.
读取操作 = Claude原生bash。写入操作 = MCP工具。