跳至主要内容

使用 GitHub Codespaces 进行拉取请求

您可以在网页浏览器或 Visual Studio Code 中使用 GitHub Codespaces 来创建拉取请求、审查拉取请求并处理审查评论。

使用代码空间处理拉取请求可让您获得 GitHub Codespaces 的全部优势。欲了解更多信息,请参阅 GitHub Codespaces 功能

关于 GitHub Codespaces 中的拉取请求

GitHub Codespaces 为您提供许多处理拉取请求所需的功能

  • Create a pull request - 您可以使用终端和 Git 命令或 “源代码管理” 视图来创建拉取请求,就像在 GitHub 上一样。如果仓库使用拉取请求模板,您也可以在 “源代码管理” 视图中使用它。
  • Open a pull request – 您可以在代码空间中打开已有的拉取请求,只要您对正在合并的分支拥有代码空间访问权限。
  • Review a pull request - 一旦您在代码空间中打开拉取请求,就可以使用 “GitHub Pull Request” 视图添加审查评论并批准拉取请求。您还可以使用 GitHub Codespaces 查看审查评论

在 Codespaces 中打开拉取请求

  1. 在仓库名称下,点击 拉取请求

    Screenshot of the main page of a repository. In the horizontal navigation bar, a tab, labeled "Pull requests," is outlined in dark orange.

  2. 在拉取请求列表中,单击您想在 Codespaces 中打开的拉取请求。

  3. 在屏幕右侧,单击 代码

  4. 在 Codespaces 选项卡中,单击.

    Screenshot of the "Code" dropdown with the "Codespaces" tab selected. The message "No codespaces" is displayed. The plus button is highlighted.

    为该拉取请求分支创建了一个代码空间,并在您默认的 GitHub Codespaces 编辑器中打开。

在 Codespaces 中审查拉取请求

  1. 将默认编辑器设置为 Visual Studio Code 或 Web 版 Visual Studio Code 后,按照前文 在 Codespaces 中打开拉取请求 的步骤,在代码空间中打开该拉取请求。

  2. 在活动栏中,单击 Git 拉取请求图标即可显示 “GitHub Pull Request” 侧边栏。仅在代码空间中打开拉取请求时,活动栏才会显示此图标。

    Screenshot of the VS Code Activity Bar. The mouse pointer is hovering over an icon displaying the tooltip "GitHub Pull Request."

    如果您在代码空间中打开了拉取请求,但活动栏未显示拉取请求图标,请确保已登录 GitHub。单击活动栏中的 GitHub 图标,然后单击 Sign in

    Screenshot of the GitHub side bar showing the "Sign in" button. The GitHub icon in the Activity Bar is highlighted with an orange outline.

  3. 要审查对特定文件所做的更改,请单击 “GitHub Pull Request” 侧边栏中的文件名。

    Screenshot of the "GitHub Pull Request" side bar. A file name is highlighted with a dark orange outline.

    这将在编辑器中显示差异视图,左侧为基准分支的文件版本,右侧为拉取请求的头部分支中的新版本文件。

  4. 要添加审查评论,单击文件右侧编辑器中行号旁的 + 符号。

    Screenshot of the diff view. In the head version of the file, on the right side of the editor, the plus sign next to a line is highlighted.

  5. 输入审查评论,然后单击 Start Review

    Screenshot of a comment being added, reading "Yes, I agree, this is clearer." The "Start Review" button is shown below the comment.

  6. 可选地,您可以建议作者在同意后点击提交的更改。要执行此操作,按住您想建议更改的第一行旁的 + 符号,然后将 + 符号拖动到想建议更改的最后一行。随后在显示的评论框中单击 Make a Suggestion

    您选择的行会复制到评论框中,您可以在其中编辑以提出更改建议。您可以在包含 ```suggestion 的行上方添加评论,以解释您的建议更改。

    单击 Add Comment 将您的建议添加到拉取请求中。

    Screenshot of a suggested change. The "Make a Suggestion" and "Add Comment" buttons are shown below the suggested change.

  7. 完成添加审查评论后,您可以在 “GitHub Pull Request” 侧边栏中添加审查摘要评论。然后可以单击 Comment and Submit,或点击下拉箭头并选择 Approve and SubmitRequest Changes and Submit

    Screenshot of the side bar showing the dropdown options "Comment and Submit," "Approve and Submit," and "Request Changes and Submit."

欲了解更多关于审查拉取请求的信息,请参阅 审查拉取请求中的提议更改

在 Codespaces 中查看审查评论

收到拉取请求的反馈后,您可以在网页浏览器或 VS Code 中 将其打开在代码空间中,以查看 审查评论。随后,您可以回复评论、添加响应或驳回审查。

© . This site is unofficial and not affiliated with GitHub, Inc.