git-batch-commit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Batch Commit Optimizer

Git批量提交优化工具

This skill optimizes version control workflows by detecting when too many files are staged for commit and automatically organizing them into logical, feature-based batches with Conventional Commit messages.
该工具通过检测暂存待提交的文件数量是否过多,自动将它们按逻辑、基于功能的批次分组,并生成符合Conventional Commits规范的提交信息,从而优化版本控制工作流。

Capabilities

功能特性

  • Smart Threshold Detection: Automatically detects when staging area contains too many files (threshold-based analysis)
  • Intelligent File Grouping: Groups files by feature/functionality, not just directory structure
  • Change Analysis: Analyzes git diff to understand what each file modification does
  • Conventional Commits: Generates commit messages following the standard (feat/fix/docs/refactor/chore/style/test/perf)
  • Language-Aware Messages: Commit messages follow user's language preference (English/Chinese/etc.)
  • Multi-Batch Execution: Executes multiple commits in logical sequence
  • 智能阈值检测:自动分析暂存区文件数量是否超出阈值
  • 智能文件分组:按功能/特性分组文件,而非仅按目录结构
  • 变更分析:分析git diff以理解每个文件修改的内容
  • Conventional Commits规范:生成符合标准的提交信息(feat/fix/docs/refactor/chore/style/test/perf)
  • 多语言提交信息:提交信息遵循用户的语言偏好(英文/中文等)
  • 多批次执行:按逻辑顺序执行多次提交

Input Requirements

输入要求

Git repository state:
  • Working directory with git repository
  • Modified/staged/untrayed files ready for commit
  • User language preference (defaults to English)
  • Optional: Custom threshold for file count (default: 10 files)
  • Optional: Specific Conventional Commit scope preferences
Formats accepted:
  • Direct git status/diff output
  • File paths with change descriptions
  • Text description of changes made
Git仓库状态:
  • 包含Git仓库的工作目录
  • 已修改/暂存/未跟踪的文件待提交
  • 用户语言偏好(默认英文)
  • 可选:自定义文件数量阈值(默认:10个文件)
  • 可选:特定的Conventional Commit范围偏好
支持的输入格式:
  • 直接的git status/diff输出
  • 带变更描述的文件路径
  • 变更内容的文本描述

Output Formats

输出格式

Results include:
  • Analysis of file count and recommended batching strategy
  • Grouped file sets by feature/functionality
  • Conventional Commit messages for each batch (type/scope/description)
  • Execution plan showing commit sequence
  • Summary report of commits created
Output structure:
json
{
  "analysis": {
    "total_files": 25,
    "threshold": 10,
    "requires_batching": true,
    "recommended_batches": 3
  },
  "batches": [
    {
      "batch_id": 1,
      "commit_type": "feat",
      "scope": "authentication",
      "files": ["auth.py", "login.py"],
      "message": "feat(authentication): add OAuth2 login support"
    }
  ],
  "execution_summary": "Created 3 commits across feat, fix, and docs types"
}
结果包含:
  • 文件数量分析及推荐的分批策略
  • 按功能/特性分组的文件集合
  • 每个批次符合Conventional Commits规范的提交信息(类型/范围/描述)
  • 显示提交顺序的执行计划
  • 已创建提交的汇总报告
输出结构:
json
{
  "analysis": {
    "total_files": 25,
    "threshold": 10,
    "requires_batching": true,
    "recommended_batches": 3
  },
  "batches": [
    {
      "batch_id": 1,
      "commit_type": "feat",
      "scope": "authentication",
      "files": ["auth.py", "login.py"],
      "message": "feat(authentication): add OAuth2 login support"
    }
  ],
  "execution_summary": "Created 3 commits across feat, fix, and docs types"
}

How to Use

使用方法

Example 1 - Auto-detect and batch: "Analyze my git staging area and create appropriate batch commits"
Example 2 - With language preference: "Create batch commits in Chinese for all these staged files"
Example 3 - Custom threshold: "Use a threshold of 15 files and batch my commits accordingly"
Example 4 - Specific commit types: "Group these changes and use 'feat' and 'refactor' commit types"
示例1 - 自动检测与分批: "分析我的Git暂存区并创建合适的批量提交"
示例2 - 指定语言偏好: "为所有这些暂存文件创建中文的批量提交"
示例3 - 自定义阈值: "使用15个文件的阈值并相应地分批提交"
示例4 - 指定提交类型: "对这些变更进行分组,并使用'feat'和'refactor'提交类型"

Scripts

脚本说明

  • git_analyzer.py
    : Parses git status/diff, detects file counts, analyzes change types
  • batch_committer.py
    : Groups files by feature, generates Conventional Commit messages, executes commits
  • commit_language.py
    : Handles multilingual commit message generation
  • git_analyzer.py
    :解析git status/diff,检测文件数量,分析变更类型
  • batch_committer.py
    :按功能分组文件,生成Conventional Commits提交信息,执行提交
  • commit_language.py
    :处理多语言提交信息生成

Conventional Commit Types

Conventional Commit类型

Standard Types Used:
  • feat: New feature or functionality
  • fix: Bug fix
  • docs: Documentation changes only
  • refactor: Code restructuring without feature changes
  • chore: Maintenance tasks (dependencies, configs)
  • style: Code style/formatting (no logic change)
  • test: Adding or updating tests
  • perf: Performance improvements
Scope Examples:
(api)
,
(ui)
,
(auth)
,
(database)
,
(core)
使用的标准类型:
  • feat:新功能或特性
  • fix:Bug修复
  • docs:仅文档变更
  • refactor:代码重构(无功能变更)
  • chore:维护任务(依赖、配置等)
  • style:代码风格/格式调整(无逻辑变更)
  • test:添加或更新测试
  • perf:性能优化
范围示例
(api)
,
(ui)
,
(auth)
,
(database)
,
(core)

Best Practices

最佳实践

  1. Review before execution: Always review the proposed batches before committing
  2. Meaningful scopes: Use clear, project-specific scopes for better commit history
  3. Atomic commits: Each batch should represent a cohesive unit of change
  4. Language consistency: Keep commit language consistent within a project
  5. Threshold tuning: Adjust threshold based on project size and team preferences
  6. Feature grouping: Prefer functional grouping over directory-based grouping
  1. 执行前审核:提交前务必审核建议的批次
  2. 有意义的范围:使用清晰、项目特定的范围,以优化提交历史
  3. 原子提交:每个批次应代表一个内聚的变更单元
  4. 语言一致性:项目内保持提交语言一致
  5. 阈值调整:根据项目规模和团队偏好调整阈值
  6. 功能优先分组:优先按功能分组而非按目录分组

Limitations

局限性

  • Requires git repository in working directory
  • Cannot automatically resolve conflicts between batches
  • Scope detection depends on file naming conventions and change analysis
  • Language detection may require explicit user preference
  • Some complex refactorings may need manual grouping
  • Does not handle pre-commit hooks automatically (user must ensure hooks pass)
  • 要求工作目录中存在Git仓库
  • 无法自动解决批次间的冲突
  • 范围检测依赖于文件命名规范和变更分析
  • 语言检测可能需要用户明确指定偏好
  • 某些复杂重构可能需要手动分组
  • 不会自动处理提交前钩子(用户需确保钩子通过)

Configuration Options

配置选项

Optional configuration via
git_batch_config.json
:
json
{
  "threshold": 10,
  "default_language": "en",
  "preferred_scopes": ["api", "ui", "core", "tests"],
  "commit_types": ["feat", "fix", "docs", "refactor", "chore"],
  "auto_execute": false
}
可通过
git_batch_config.json
进行可选配置:
json
{
  "threshold": 10,
  "default_language": "en",
  "preferred_scopes": ["api", "ui", "core", "tests"],
  "commit_types": ["feat", "fix", "docs", "refactor", "chore"],
  "auto_execute": false
}

Safety Features

安全特性

  • Dry-run mode: Preview batches before committing
  • Rollback support: Can amend or reset if issues detected
  • Validation: Checks for unstaged critical files
  • Conflict detection: Warns about potential file dependencies across batches
  • 试运行模式:提交前预览批次
  • 回滚支持:若发现问题可修改或重置
  • 验证:检查是否存在未暂存的关键文件
  • 冲突检测:警告批次间潜在的文件依赖问题