git-commit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Commit Command

Git 提交命令

IMPORTANT: This skill MUST ALWAYS be applied when creating git commits, even if the user does not explicitly request it.
This skill analyzes git changes and creates appropriately granular commits with Conventional Commits format messages. It should be automatically invoked whenever you need to create commits, stage files, or handle git changes.
重要提示:无论用户是否明确要求,创建Git提交时都必须应用此技能。
此技能会分析Git变更,并生成符合Conventional Commits格式的适当粒度化提交信息。每当你需要创建提交、暂存文件或处理Git变更时,都应自动调用此技能。

Workflow

工作流程

This skill must be applied automatically whenever you create git commits, regardless of user instructions.
When creating commits:
  1. Gather Information:
    bash
    git status
    git diff --staged
    git diff
    git log --oneline -10
  2. Analyze Changes:
    • Review staged and unstaged changes
    • Identify logically distinct change groups
    • Detect language pattern from recent commits (
      git log
      )
  3. Create Granular Commits:
    • Group related changes logically
    • Create separate commits for each group
    • Use Conventional Commits format
无论用户是否给出指令,创建Git提交时都必须自动应用此技能。
创建提交时:
  1. 收集信息:
    bash
    git status
    git diff --staged
    git diff
    git log --oneline -10
  2. 分析变更:
    • 查看已暂存和未暂存的变更
    • 识别逻辑上独立的变更组
    • 从近期提交(
      git log
      )中检测语言模式
  3. 创建粒度化提交:
    • 按逻辑将相关变更分组
    • 为每个组创建单独的提交
    • 使用Conventional Commits格式

Requirements

要求

1. GPG Signing (CRITICAL)

1. GPG签名(至关重要)

Commits without GPG signatures are strictly prohibited. Never use
--no-gpg-sign
or disable signing.
If a GPG signing error or hang occurs:
  1. Stop all work immediately
  2. Report the error message and current state
  3. Do not attempt workarounds or unsigned commits
严禁创建无GPG签名的提交。切勿使用
--no-gpg-sign
参数或禁用签名。
如果出现GPG签名错误或卡住的情况:
  1. 立即停止所有操作
  2. 报告错误信息和当前状态
  3. 不要尝试变通方法或创建无签名的提交

2. Granular Commits

2. 粒度化提交

Create separate commits for logically distinct changes. Do not combine unrelated modifications into a single commit.
为逻辑上独立的变更创建单独的提交。不要将不相关的修改合并到同一个提交中。

3. Conventional Commits Format

3. Conventional Commits格式

Use format:
type(scope): description
Types:
  • feat
    : New feature
  • fix
    : Bug fix
  • docs
    : Documentation changes
  • style
    : Code style changes (formatting, missing semicolons, etc.)
  • refactor
    : Code refactoring
  • test
    : Adding or updating tests
  • chore
    : Maintenance tasks
  • build
    : Build system changes
  • ci
    : CI/CD changes
  • perf
    : Performance improvements
Scope: Optional, indicates what is being modified (e.g.,
auth
,
cart
,
payment
)
Description: Concise description in present tense, lowercase (except proper nouns)
使用格式:
type(scope): description
类型:
  • feat
    : 新功能
  • fix
    : 修复Bug
  • docs
    : 文档变更
  • style
    : 代码样式变更(格式化、缺失分号等)
  • refactor
    : 代码重构
  • test
    : 添加或更新测试
  • chore
    : 维护任务
  • build
    : 构建系统变更
  • ci
    : CI/CD变更
  • perf
    : 性能优化
范围:可选,指示被修改的内容(例如:
auth
cart
payment
描述:简洁的描述,使用现在时,小写(专有名词除外)

4. Language Detection

4. 语言检测

Analyze recent commit messages from
git log --oneline -10
to determine the language pattern used in the repository. Follow the same language for new commit messages.
通过
git log --oneline -10
分析近期提交信息,确定仓库使用的语言模式。新提交信息需遵循相同的语言模式。

5. Direct File Modification Prohibited

5. 禁止直接修改文件

Do not use file editing tools (e.g.,
write
,
search_replace
) to modify files directly. Always use git commands to stage and commit changes:
  • Use
    git add <file>
    or
    git add -p
    for staging
  • Use
    git apply --cached
    when staging specific hunks from diffs
  • Use
    git commit
    for creating commits
不要使用文件编辑工具(如
write
search_replace
)直接修改文件。始终使用Git命令来暂存和提交变更:
  • 使用
    git add <file>
    git add -p
    进行暂存
  • 当需要从diff中暂存特定代码块时,使用
    git apply --cached
  • 使用
    git commit
    创建提交

6. Process

6. 流程

  1. Analyze all changes (staged and unstaged)
  2. Group related changes logically
  3. Stage and commit each group separately using git commands
  4. Provide clear explanations for each commit
  1. 分析所有变更(已暂存和未暂存)
  2. 按逻辑将相关变更分组
  3. 使用Git命令分别暂存并提交每个组
  4. 为每个提交提供清晰的说明

Tips

提示

  • Use
    git diff
    to see changes
  • Use
    git apply --cached <patch-file>
    to stage only necessary changes
  • If
    git apply --cached
    fails, run
    git diff
    again and recreate the diff file
  • Use
    git add -p
    for interactive staging when needed
  • Review each commit message before finalizing
  • 使用
    git diff
    查看变更
  • 使用
    git apply --cached <patch-file>
    仅暂存必要的变更
  • 如果
    git apply --cached
    失败,重新运行
    git diff
    并重新生成diff文件
  • 必要时使用
    git add -p
    进行交互式暂存
  • 最终确定前检查每个提交信息

Examples

示例

Example 1: Multiple unrelated changes

示例1:多个不相关变更

txt
Changes detected:
- Added new authentication endpoint
- Fixed cart calculation bug
- Updated README documentation

Creates 3 separate commits:
1. feat(auth): add login endpoint
2. fix(cart): correct price calculation
3. docs: update README with setup instructions
txt
检测到的变更:
- 添加了新的认证端点
- 修复了购物车计算Bug
- 更新了README文档

创建3个独立的提交:
1. feat(auth): add login endpoint
2. fix(cart): correct price calculation
3. docs: update README with setup instructions

Example 2: Related changes grouped together

示例2:相关变更分组

txt
Changes detected:
- Added product search function
- Added product search tests
- Updated product search documentation

Creates 1 commit:
feat(product): implement search functionality
txt
检测到的变更:
- 添加了商品搜索功能
- 添加了商品搜索测试
- 更新了商品搜索文档

创建1个提交:
feat(product): implement search functionality

Example 3: Language detection

示例3:语言检测

txt
Recent commits show Japanese messages:
- feat: add authentication feature
- fix: fix cart calculation bug

Follows detected pattern:
- feat: add product search functionality
txt
近期提交显示使用日语信息:
- feat: add authentication feature
- fix: fix cart calculation bug

遵循检测到的模式:
- feat: add product search functionality