git

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Skill

Git Skill

Code is Mechanism, Prompt is Policy
代码是机制,提示词是策略

Architecture

架构说明

This skill uses
@skill_command
decorator in
scripts/*.py
files. Commands are automatically exposed via MCP as
git.command_name
.
本Skill在
scripts/*.py
文件中使用
@skill_command
装饰器。命令会通过MCP自动暴露为
git.command_name
格式。

Available Commands

可用命令

CommandDescription
git.status
Show working tree status
git.stage_all
Stage all changes (with security scan)
git.commit
Commit staged changes
git.smart_commit
Smart Commit workflow (stage → scan → approve → commit)
git.push
Push to remote
git.log
Show commit logs
命令描述
git.status
显示工作区状态
git.stage_all
暂存所有变更(含安全扫描)
git.commit
提交已暂存的变更
git.smart_commit
智能提交流程(暂存 → 扫描 → 审批 → 提交)
git.push
推送到远程仓库
git.log
显示提交日志

Smart Commit Workflow

智能提交流程

Use
git.smart_commit
for secure, human-in-the-loop commits:
python
undefined
使用
git.smart_commit
实现安全的、需人工参与的提交流程:
python
undefined

Step 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
stage_and_scan
function provides automatic staging with security validation:
Stage All Files → Security Scan → Lefthook Pre-commit → Finalize
stage_and_scan
函数提供带安全验证的自动暂存功能:
暂存所有文件 → 安全扫描 → Lefthook预提交检查 → 完成

Key Features

核心特性

  1. Automatic Staging
    python
    stage_and_scan(project_root=".")
    # Returns: {staged_files, diff, security_issues, lefthook_error}
  2. Security Scanning
    • Detects sensitive files (
      .env*
      ,
      *.pem
      ,
      *.key
      ,
      *.secret
      , etc.)
    • Automatically un-stages detected files
    • Returns list of security issues
  3. Lefthook Integration
    • Runs pre-commit hooks after staging
    • Re-stages files modified by lefthook formatters
    • Returns lefthook output for review
  1. 自动暂存
    python
    stage_and_scan(project_root=".")
    # 返回: {staged_files, diff, security_issues, lefthook_error}
  2. 安全扫描
    • 检测敏感文件(
      .env*
      ,
      *.pem
      ,
      *.key
      ,
      *.secret
      等)
    • 自动取消检测到的敏感文件的暂存状态
    • 返回安全问题列表
  3. Lefthook集成
    • 暂存后运行预提交钩子
    • 重新暂存由Lefthook格式化工具修改的文件
    • 返回Lefthook输出结果供审核

Staged Files Commands

暂存文件相关命令

CommandDescription
git.stage_all()
Stage all changes with security scan
git.status()
Show staged files and working tree status
git.diff()
Show staged diff
命令描述
git.stage_all()
暂存所有变更(含安全扫描)
git.status()
显示已暂存文件和工作区状态
git.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.yml

Usage Guidelines

使用指南

Read Operations (Safe - Use Claude-native bash)

读取操作(安全操作 - 使用Claude原生bash)

bash
git status
git diff --cached
git diff
git log --oneline
bash
git status
git diff --cached
git diff
git log --oneline

Write Operations (Use MCP Tools)

写入操作(使用MCP工具)

OperationTool
Stage all
git.stage_all()
(scans for secrets)
Commit
git.commit(message="...")
Push
git.push()
Smart Commit
git.smart_commit(action="start")
操作工具
暂存所有变更
git.stage_all()
(扫描敏感信息)
提交
git.commit(message="...")
推送至远程
git.push()
智能提交
git.smart_commit(action="start")

Key Principle

核心原则

Read = Claude-native bash. Write = MCP tools.
读取操作 = Claude原生bash。写入操作 = MCP工具。