git
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit
Git
Commits
提交
Grouping
分组
- Group changes into cohesive commits by unit of work: one commit per logical change that could be deployed, reverted, or cherry-picked independently.
- When a diff spans multiple concerns (feature + refactor, fix + test, rename + behavior change), split into separate commits. Stage files selectively with .
git add <paths> - Ask yourself: "if this commit were reverted, would exactly one coherent thing disappear?" If not, split it.
- 按工作单元将改动分组为内聚的提交:每个可独立部署、回滚或cherry-pick的逻辑改动对应一个提交。
- 当一个diff涉及多个关注点(功能+重构、修复+测试、重命名+行为变更)时,拆分为独立提交。使用选择性暂存文件。
git add <paths> - 自问:"如果回滚这个提交,是不是刚好只会移除一个完整的逻辑改动?"如果不是,就拆分提交。
Conventional Commit Format
约定式提交格式
<type>[scope]: <description>
[body]
[footer]Types: , , , , , , , , , , .
featfixdocsstylerefactorperftestbuildcichorerevert- Derive type and scope from the diff, not from the user's words.
- Description: imperative mood, present tense, under 72 chars. "add", not "added" or "adds".
- Body: explain why, not what. The diff already shows the what.
- Breaking changes: add after type/scope and a
!footer.BREAKING CHANGE: - Reference issues in the footer: ,
Closes #123.Refs #456
<type>[scope]: <description>
[body]
[footer]类型:, , , , , , , , , , 。
featfixdocsstylerefactorperftestbuildcichorerevert- 从diff推导类型和作用域,不要依据用户的口头描述。
- 描述:使用祈使语气、现在时态,长度不超过72个字符。用"add",不要用"added"或"adds"。
- 正文:解释为什么做改动,而不是做了什么改动。diff已经展示了改动内容。
- 破坏性变更:在类型/作用域后添加,并在页脚添加
!说明。BREAKING CHANGE: - 在页脚关联issue:,
Closes #123。Refs #456
Authoring
提交人信息
- Read author name and email from and
git config user.namebefore every commit. Use those values exclusively - never substitute another identity.git config user.email - Commits are the user's work. Omit trailers for LLMs.
Co-Authored-By - Honor the user's signing config (,
commit.gpgsign). Never passuser.signingkeyor--no-gpg-sign.-c commit.gpgsign=false
- 每次提交前从和
git config user.name读取提交人姓名和邮箱。仅使用这些值,绝对不要替换为其他身份。git config user.email - 提交属于用户的工作成果。不要为LLM添加标识。
Co-Authored-By - 遵守用户的签名配置(、
commit.gpgsign)。绝对不要使用user.signingkey或--no-gpg-sign参数。-c commit.gpgsign=false
Safety
安全注意事项
- Read (or
git diff --stagedwhen nothing is staged) andgit diffbefore committing.git status --porcelain - Stage files explicitly by path. Avoid or
git add -Ato prevent leaking secrets or binaries.git add . - Leave hooks enabled. When a hook fails, fix the issue and create a new commit - never amend the failed one.
- Reserve destructive commands (,
--force,reset --hard,clean -f) for explicit user requests.branch -D
- 提交前读取(无暂存内容时读取
git diff --staged)和git diff的输出。git status --porcelain - 明确按路径暂存文件。避免使用或
git add -A,防止泄露密钥或二进制文件。git add . - 保持钩子启用状态。如果钩子执行失败,修复问题后创建新提交——绝对不要amend执行失败的提交。
- 破坏性命令(、
--force、reset --hard、clean -f)仅在用户明确要求时使用。branch -D
Pull Requests
拉取请求(PR)
Title
标题
- Use conventional commit format: .
<type>[scope]: <description> - Keep under 70 characters. Put detail in the body.
- 使用约定式提交格式:。
<type>[scope]: <description> - 长度保持在70个字符以内,详细内容放在正文中。
Body
正文
undefinedundefinedSummary
Summary
<1-3 bullet points explaining why this change exists>
<1-3条要点说明该变更的存在原因>
Changes
Changes
<Bullet list of what changed, grouped logically>
<按逻辑分组的改动列表>
Test plan
Test plan
<How to verify correctness>
```
- Write the summary from all commits on the branch, not just the latest one.
- Link related issues: ,
Closes #N.Refs #N
<如何验证变更正确性>
- 基于分支上的所有提交撰写摘要,不要仅参考最新提交。
- 关联相关issue:`Closes #N`, `Refs #N`。gh CLI
gh CLI
- Use with a heredoc for multi-line bodies.
gh pr create --title "..." --body "..." - Use ,
gh pr view,gh pr checksfor PR lifecycle management.gh pr merge - Use ,
gh issue listfor issue context before writing PR descriptions.gh issue view - Push with before creating a PR when the remote branch is missing.
git push -u origin HEAD
- 使用命令,多行正文使用heredoc传入。
gh pr create --title "..." --body "..." - 使用、
gh pr view、gh pr checks管理PR生命周期。gh pr merge - 编写PR描述前,使用、
gh issue list获取issue上下文。gh issue view - 当远程分支不存在时,创建PR前先执行推送代码。
git push -u origin HEAD