git-commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAutomated Git Commits
自动化Git提交
This skill provides instructions for performing atomic, well-structured Git commits following the Conventional Commits specification.
本技能提供遵循Conventional Commits规范执行原子化、结构清晰的Git提交的指导说明。
1. Analyze Changes
1. 分析变更
- Identify Modified Files: Run to see all staged and unstaged changes.
git status --short - Respect Ignore Rules: Do NOT include files that the user has explicitly requested to ignore or that match patterns.
.gitignore - Group by Scope: Group modified files by their logical "scope" (e.g., a specific module, feature, or layer like ,
data,domain).ui
- 识别修改文件:运行查看所有已暂存和未暂存的变更。
git status --short - 遵守忽略规则:不要包含用户明确要求忽略或者匹配规则的文件。
.gitignore - 按范围分组:按照逻辑“范围”对修改的文件分组(例如特定模块、功能,或者、
data、domain这类层级)。ui
2. Branching
2. 分支管理
- Feature Branches: ALWAYS create descriptive feature branches from (e.g.,
main).feat/login-logic - Merge Flow: Merge back into only after passing all quality checks and PR approval.
main
- 功能分支:始终从分支创建描述清晰的功能分支(例如
main)。feat/login-logic - 合并流程:仅在通过所有质量检查和PR审批后才能合并回分支。
main
3. Generate Commit Message
3. 生成提交信息
- Conventional Commits: Each commit MUST follow the pattern: .
<type>(<scope>): <message>- Types: ,
feat,fix,docs,style,refactor,perf,test,build,ci,chore.revert - Scope: The module or area being changed (e.g., ,
auth).api - Message: A concise description in imperative mood.
- Types:
- Sub-messages (Commit Body):
- ALWAYS include a detailed body if the change involves logic, breaking changes, or multiple steps.
- Explain the "What", "Why", and "How" of the change.
- Use blank lines to separate the subject from the body.
- Conventional Commits:每次提交必须遵循以下格式:。
<type>(<scope>): <message>- 类型:、
feat、fix、docs、style、refactor、perf、test、build、ci、chore。revert - 范围:被修改的模块或领域(例如、
auth)。api - 信息:用祈使语气编写的简洁描述。
- 类型:
- 子信息(提交正文):
- 如果变更涉及逻辑、破坏性改动或多步操作,必须包含详细的正文。
- 说明变更的“内容”、“原因”和“实现方式”。
- 使用空行分隔提交主题和正文。
3. Atomic Commits
3. 原子化提交
- One Scope per Commit: Perform separate commits for different scopes.
- Stage Selectively: Stage only the files belonging to the current scope.
- 单次提交仅覆盖一个范围:不同范围的变更要分开提交。
- 选择性暂存:仅暂存属于当前范围的文件。
4. Execution Flow
4. 执行流程
- Step 1: Group files by scope.
- Step 2: For each group:
- Stage the files.
- Generate the conventional commit message (subject + body).
- Execute:
bash
git commit -m "<subject>" -m "<body>"
- Step 3: Verify history ().
git log -n 5
- 步骤1:按范围对文件分组。
- 步骤2:对每个分组:
- 暂存文件。
- 生成符合Conventional Commits规范的提交信息(主题+正文)。
- 执行:
bash
git commit -m "<subject>" -m "<body>"
- 步骤3:验证提交历史()。
git log -n 5