git-commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit 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:
-
Gather Information:bash
git status git diff --staged git diff git log --oneline -10 -
Analyze Changes:
- Review staged and unstaged changes
- Identify logically distinct change groups
- Detect language pattern from recent commits ()
git log
-
Create Granular Commits:
- Group related changes logically
- Create separate commits for each group
- Use Conventional Commits format
无论用户是否给出指令,创建Git提交时都必须自动应用此技能。
创建提交时:
-
收集信息:bash
git status git diff --staged git diff git log --oneline -10 -
分析变更:
- 查看已暂存和未暂存的变更
- 识别逻辑上独立的变更组
- 从近期提交()中检测语言模式
git log
-
创建粒度化提交:
- 按逻辑将相关变更分组
- 为每个组创建单独的提交
- 使用Conventional Commits格式
Requirements
要求
1. GPG Signing (CRITICAL)
1. GPG签名(至关重要)
Commits without GPG signatures are strictly prohibited. Never use or disable signing.
--no-gpg-signIf a GPG signing error or hang occurs:
- Stop all work immediately
- Report the error message and current state
- Do not attempt workarounds or unsigned commits
严禁创建无GPG签名的提交。切勿使用参数或禁用签名。
--no-gpg-sign如果出现GPG签名错误或卡住的情况:
- 立即停止所有操作
- 报告错误信息和当前状态
- 不要尝试变通方法或创建无签名的提交
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): descriptionTypes:
- : New feature
feat - : Bug fix
fix - : Documentation changes
docs - : Code style changes (formatting, missing semicolons, etc.)
style - : Code refactoring
refactor - : Adding or updating tests
test - : Maintenance tasks
chore - : Build system changes
build - : CI/CD changes
ci - : Performance improvements
perf
Scope: Optional, indicates what is being modified (e.g., , , )
authcartpaymentDescription: Concise description in present tense, lowercase (except proper nouns)
使用格式:
type(scope): description类型:
- : 新功能
feat - : 修复Bug
fix - : 文档变更
docs - : 代码样式变更(格式化、缺失分号等)
style - : 代码重构
refactor - : 添加或更新测试
test - : 维护任务
chore - : 构建系统变更
build - : CI/CD变更
ci - : 性能优化
perf
范围:可选,指示被修改的内容(例如:、、)
authcartpayment描述:简洁的描述,使用现在时,小写(专有名词除外)
4. Language Detection
4. 语言检测
Analyze recent commit messages from to determine the language pattern used in the repository. Follow the same language for new commit messages.
git log --oneline -10通过分析近期提交信息,确定仓库使用的语言模式。新提交信息需遵循相同的语言模式。
git log --oneline -105. Direct File Modification Prohibited
5. 禁止直接修改文件
Do not use file editing tools (e.g., , ) to modify files directly. Always use git commands to stage and commit changes:
writesearch_replace- Use or
git add <file>for staginggit add -p - Use when staging specific hunks from diffs
git apply --cached - Use for creating commits
git commit
不要使用文件编辑工具(如、)直接修改文件。始终使用Git命令来暂存和提交变更:
writesearch_replace- 使用或
git add <file>进行暂存git add -p - 当需要从diff中暂存特定代码块时,使用
git apply --cached - 使用创建提交
git commit
6. Process
6. 流程
- Analyze all changes (staged and unstaged)
- Group related changes logically
- Stage and commit each group separately using git commands
- Provide clear explanations for each commit
- 分析所有变更(已暂存和未暂存)
- 按逻辑将相关变更分组
- 使用Git命令分别暂存并提交每个组
- 为每个提交提供清晰的说明
Tips
提示
- Use to see changes
git diff - Use to stage only necessary changes
git apply --cached <patch-file> - If fails, run
git apply --cachedagain and recreate the diff filegit diff - Use for interactive staging when needed
git add -p - Review each commit message before finalizing
- 使用查看变更
git diff - 使用仅暂存必要的变更
git apply --cached <patch-file> - 如果失败,重新运行
git apply --cached并重新生成diff文件git 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 instructionstxt
检测到的变更:
- 添加了新的认证端点
- 修复了购物车计算Bug
- 更新了README文档
创建3个独立的提交:
1. feat(auth): add login endpoint
2. fix(cart): correct price calculation
3. docs: update README with setup instructionsExample 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 functionalitytxt
检测到的变更:
- 添加了商品搜索功能
- 添加了商品搜索测试
- 更新了商品搜索文档
创建1个提交:
feat(product): implement search functionalityExample 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 functionalitytxt
近期提交显示使用日语信息:
- feat: add authentication feature
- fix: fix cart calculation bug
遵循检测到的模式:
- feat: add product search functionality