Skip to content

本页由 AI 根据韩语原文翻译,可能存在错误。

第6章 PR 与评审——合并之前再看一遍 ​

必读 想跟着这个阶段学下去,一定要读这一章。

一句话总结:PR(Pull Request)是提议把我分支上的改动合并进 main。它为合并之前的讨论和审查,留出了一个位置。 一个人做也要评审。AI 评审(/code-review)也可以让它做,但**"没有问题"不等于安全,合不合并由我来决定。**

这一章依据 2026年11月1日确认的 GitHub、Claude Code 官方文档写成。

什么是 PR ​

PR 是提议把一个分支的改动合并进另一个分支。在改动进入项目之前,它留出了一个讨论和审查的位置。[1]

PR 画面里有这些标签页。[2]

标签页显示什么
Conversation说明、评论、评审
Commits分支变化的过程
Checks自动测试、构建结果(第5章)
Files changed评审者针对改动内容发表意见的地方

来源:GitHub 官方文档(只摘录了一部分)[2:1]

创建 PR 时,要写明改了什么、解决什么问题。[3]

以后在第8章里会用到 Issue(GitHub 上用来记下待办事项或 bug 的记录)。如果是解决某个 Issue 的 PR,就在 PR 说明里用 fixes #编号 这样规定的词写上这个 Issue,把它们关联起来。这样 PR 合并时,那个 Issue 就会自动关闭。[3:1] 现在只要知道有这种关联就行了。

小的 PR 更容易评审,合并也更安全。 在请别人评审之前,先自己检查。读一遍改动的内容,看有没有不小心改动的地方,确认构建和测试是否运行过了。[4]

也可以请 Claude Code 帮你创建 PR。官方文档建议,提交之前先审查 Claude 创建的 PR,并请它指出有风险的地方。[5]

用 first-board 分支创建 PR。提交之前,先指出这次改动里可能有风险的地方。

理解检查

关于 PR(Pull Request),哪种说法是对的?

一个人也要评审 ​

GitHub 教程说,即使一个人工作,在合并之前有意识地做评审,这个习惯会让项目保持健康,也会让以后的协作更容易。[6]

评审以三种决定之一结束。[7]

决定意思
Comment只留下意见
Approve可以合并了
Request changes合并之前必须修改

来源:GitHub 官方文档[7:1]

评审的标准是第3章的 SPEC.md。Claude Code 官方最佳实践文档举例说,做完之后要这样评审。[8]

  • 对照 SPEC.md,看所有要求是否都已实现。
  • 只报告影响正确性的缺口。
  • 字的样子、起名字这类风格问题跳过。

为什么要跳过风格问题?让评审者找问题,它总会找出点什么。[9] 把这些全都改一遍,就会冒出一堆多余的累赘。只让它看正确性,留下的就只有必须改的地方。

在新会话里,把当前分支的改动对照 SPEC.md 做评审。看要求是否都已实现,每条确认标准是否都有检查,只告诉我影响正确性的缺口。跳过风格问题。

理解检查

对照 SPEC.md 做评审时,官方文档为什么说“风格可以跳过”?

请 AI 来评审 ​

Claude Code 里有评审命令 /code-review。在工作中的会话里输入它,它会读取我分支上的改动,找出正确性问题,并在对话里告诉我。[10] 任何套餐都能用。[11]

比如做完第一个画面后,只要在输入框里输入 /code-review 就行了。不用另外加说明,它也会去看当前分支的改动。

AI 评审有明确的局限。

  • AI 评审可能漏掉 bug 或安全问题。没有发现,并不意味着没有错误,也不意味着安全。[12]
  • 自动在 GitHub PR 上加评审的托管式评审,也不会批准或阻止 PR。合不合并由人来决定。[13]
详细说明(点击展开)
  • 用量:评审也是在我的会话里运行的,所以和会话的其余部分一样,按我的套餐用量计算。[14]
  • 桌面应用:提交之前可以在输入框里输入 /code-review 来获得评审。[15] 打开 PR 之后,可以在会话信息面板里看到 PR 和自动检查的状态。这个功能需要安装并登录 GitHub CLI(gh,用命令来操作 GitHub 的程序)。[16]
  • 托管式评审:自动在 GitHub PR 上加评审的功能是给 Team、Enterprise 套餐用的。个人在任何套餐里都可以用 /code-review。[11:1]

如果你在第3阶段学过"写的人和确认的人分开",那么即使是同一个 Claude,也最好让它在新会话里评审。因为这样它不会被制作时那段对话的上下文牵着走。

理解检查

在 AI 评审中没有发现问题时,该怎么看待?

合并并收尾 ​

评审完毕、确认手段也通过了,就把 PR 合并(Merge)。GitHub flow 的最后一步是删除分支。就算删了分支,PR 和提交记录也不会被删除,所以不用担心。[17]

以后人多了,可以设置"必须有批准才能合并"这样的保护规则。[18] 现在一个人练习,不用管它。

理解检查

合并 PR 之后把分支删掉,会怎样?

动手试试 ​

  1. 确认 first-board 分支已经上传到 GitHub(第4章)。在仓库首页点 Pull requests → New pull request,选 first-board 作为要比较的分支,然后点 Create pull request。[19] 在标题和说明里写清楚改了什么、为什么改。
  2. 创建之前,请 Claude 指出有风险的地方。
  3. 在新会话里,对照 SPEC.md 获得评审。只修改正确性问题。
  4. 再让 /code-review 评审一次,就算没有发现,也亲自浏览一遍 Files changed 标签页。
  5. 确认手段通过后,合并 PR,并整理分支。

连续任务:第7章里,我们会把合并好的待办看板,用 GitHub Pages 发布到互联网上。

总结 ​

  • PR 是合并之前讨论和审查的地方。做小一点,写明改了什么、为什么改,并先自己审查。
  • 一个人也要评审。标准是 SPEC.md,只修改正确性缺口,跳过风格。
  • /code-review 在任何套餐里都能用。没有发现不等于安全,合不合并由人来决定。
  • 合并之后就算删了分支,PR 和提交记录也还在。

术语整理 ​

术语中文名称一句话解释
Pull Request(PR)拉取请求提议合并分支改动的请求
Review评审合并之前审查改动
Merge合并把分支的改动合并进来
/code-review代码评审Claude Code 的评审命令

这一章读完了吗?

学习记录只保存在这个浏览器中。整体进度可以在 全部目录中查看。

下一章:第7章. 发布

参考资料(19 条)
  1. GitHub 官方文档,「About pull requests」。 "A pull request proposes merging code changes from one branch into another. As a collaborative feature, pull requests give you a place to discuss and review work before it becomes part of a project." docs.github.com (确认日期 2026-11-01) ↩︎

  2. GitHub 官方文档,「About pull requests」。 "Checks shows the results of automated tests, builds, and other validations." / "Files changed shows the diff that reviewers comment on." docs.github.com (确认日期 2026-11-01) ↩︎

  3. GitHub 官方文档,「GitHub flow」。 "When you create a pull request, include a summary of the changes and what problem they solve." / "If you link with a keyword, the issue will close automatically when the pull request merges." docs.github.com (确认日期 2026-11-01) ↩︎

  4. GitHub 官方文档,「Helping others review your changes」。 "Small, focused pull requests are easier to review and safer to merge." / "A self-review can include reading the diff, checking for accidental changes, and making sure relevant builds or tests have run." docs.github.com (确认日期 2026-11-01) ↩︎

  5. Claude Code 官方文档,「Common workflows」。 "Review Claude's generated PR before submitting and ask Claude to highlight potential risks or considerations." code.claude.com (确认日期 2026-11-01) ↩︎

  6. GitHub 官方文档,「Reviewing your proposed changes」。 "Even when you work alone, a deliberate review builds a habit that keeps your software projects healthy and makes collaboration easier later." docs.github.com (确认日期 2026-11-01) ↩︎

  7. GitHub 官方文档,「Quickstart for reviewing pull requests」。 "Approve signals that the changes are ready to merge." / "Request changes flags feedback the author must address before merging." docs.github.com (确认日期 2026-11-01) ↩︎

  8. 官方示例是把这次评审交给子代理(subagent,Claude 把工作单独拆出去交给的另一个 Claude)去做,本指南改成用新会话。Claude Code 官方文档,「Best practices for Claude Code」。 "use a subagent to review the rate limiter diff against SPEC.md, check every requirement is implemented and the listed edge cases have tests, report gaps that affect correctness and skip style" code.claude.com (确认日期 2026-11-01) ↩︎

  9. Claude Code 官方文档,「Best practices for Claude Code」。 "A reviewer that's asked to find problems will always find something." code.claude.com (确认日期 2026-11-01) ↩︎

  10. Claude Code 官方文档,「Review locally with /code-review」。 "Claude reviews the changes on your branch, looks for correctness bugs, and reports what it found in your conversation." code.claude.com (确认日期 2026-11-01) ↩︎

  11. Claude Code 官方文档,「Code Review」。 "Plans: Team and Enterprise" / "Run /code-review in your Claude Code session on any plan, or compare all the options." code.claude.com (确认日期 2026-11-01) ↩︎

  12. Claude Code 官方文档,「Code Review」。 "Code Review uses AI to review code and may miss bugs, security vulnerabilities, or other issues. A review with no findings doesn't mean your code is error-free or secure." code.claude.com (确认日期 2026-11-01) ↩︎

  13. Claude Code 官方文档,「Code Review」。 "A review never approves or blocks the pull request, so the decision to merge stays with your team." code.claude.com (确认日期 2026-11-01) ↩︎

  14. Claude Code 官方文档,「Review locally with /code-review」。 "The review runs in your own session, so it counts toward your plan's usage or API billing the same way the rest of the session does." code.claude.com (确认日期 2026-11-01) ↩︎

  15. Claude Code 官方文档,「Desktop application」。 "To have Claude review your changes before you commit, enter /code-review in the prompt box." code.claude.com (确认日期 2026-11-01) ↩︎

  16. Claude Code 官方文档,「Desktop application」。 "After you open a pull request, it appears in the Changes card of the session details panel with the status of its CI checks." / "PR monitoring requires the GitHub CLI (gh) to be installed and authenticated on your machine." code.claude.com (确认日期 2026-11-01) ↩︎

  17. GitHub 官方文档,「GitHub flow」。 "Don't worry about losing information. Your pull request and commit history will not be deleted." docs.github.com (确认日期 2026-11-01) ↩︎

  18. 保护规则默认会禁止强制覆盖(force push,硬把记录覆盖上传)和删除分支。GitHub 官方文档,「About protected branches」。 "By default, each branch protection rule disables force pushes to the matching branches and prevents the matching branches from being deleted." docs.github.com (确认日期 2026-11-01) ↩︎

  19. GitHub 官方文档,「Quickstart for pull requests」。 "then click New pull request." / "For the compare branch, select the branch that contains your changes." / "Click Create pull request." docs.github.com (确认日期 2026-11-01) ↩︎