The Wayback Machine - https://web.archive.org/web/20211009130253/https://docs.github.com/cn/codespaces/developing-in-codespaces/using-codespaces-in-visual-studio-code

在 Visual Studio Code 中使用代码空间

您可以将 GitHub Codespaces 扩展连接到您在 GitHub 上的帐户,直接在 Visual Studio Code 代码空间中开发。

Codespaces is available for organizations using GitHub Team or GitHub Enterprise Cloud. 更多信息请参阅“GitHub 的产品”。

基本要求

要直接在 Visual Studio Code 中开发代码空间,必须登录到 GitHub Codespaces 扩展。 GitHub Codespaces 扩展需要 Visual Studio Code 2020 年 10 月 1 日版本 1.51 或更高版本。

使用 Visual Studio Marketplace 安装 GitHub Codespaces 扩展。 更多信息请参阅 Visual Studio Code 文档中的扩展 Marketplace

  1. 在 Visual Studio Code 中,从左侧边栏单击 Remote Explorer 图标。 Visual Studio Code 中的 Remote Explorer 图标
  2. 单击 Sign in to view GitHub...(登录以查看 Codespaces...)登录以查看 Codespaces
  3. 要授权 Visual Studio Code 访问您在 GitHub 上的帐户,请单击 Allow(允许)
  4. 登录 GitHub 以审批扩展。
  1. 在 Visual Studio Code 中,从左侧边栏单击 Remote Explorer 图标。 Visual Studio Code 中的 Remote Explorer 图标
  2. 使用“REMOTE EXPLORER(远程资源管理器)”下拉列表,然后单击 GitHub CodespacesCodespaces 标头
  3. 单击 Sign in to view Codespaces...(登录以查看 Codespaces...)登录以查看 Codespaces
  4. 要授权 Visual Studio Code 访问您在 GitHub 上的帐户,请单击 Allow(允许)
  5. 登录 GitHub 以审批扩展。

在 Visual Studio Code 中创建代码空间

将 GitHub 帐户连接到 GitHub Codespaces 扩展后,您可以在 Visual Studio Code 或 GitHub 上创建的代码空间中进行开发。

  1. 在 Visual Studio Code 中,从左侧边栏单击 Remote Explorer 图标。 Visual Studio Code 中的 Remote Explorer 图标
  2. 单击 Add(添加)图标,然后单击 Create New Codespace(创建新代码空间)Codespaces 中的 Create new Codespace(创建新代码空间)选项
  3. 键入,然后单击要在其中开发仓库的名称。 搜索仓库以创建新的 Codespaces
  4. 单击要在其中开发的分支。 搜索分支以创建新的 Codespaces
  5. Click the machine type you want to develop in. 新 Codespaces 的实例类型

在 Visual Studio Code 中打开代码空间

  1. 在 Visual Studio Code 中,从左侧边栏单击 Remote Explorer 图标。 Visual Studio Code 中的 Remote Explorer 图标
  2. 在“Codespaces(代码空间)”下,单击您要在其中开发的代码空间。
  3. 单击 Connect to Codespace(连接到代码空间)图标。 Visual Studio Code 中的连接到代码空间图标

在 Visual Studio Code 中更改机器类型

You can run your codespace on a choice of remote machine, from 2 cores to 32 cores. 每种类型都有不同的资源水平和不同的计费等级。 For information, see "About billing for Codespaces."

您可以随时更改代码空间的机器类型。

  1. 在 Visual Studio Code 中,打开命令调色板 (shift command P / shift control P)。
  2. 搜索并选择“代码空间:更改机器类型”。 搜索分支以创建新的 Codespaces
  3. 单击您要更改的代码空间。 搜索分支以创建新的 Codespaces
  4. Choose the machine type you want to use.

如果代码空间正在运行,则会显示一条消息,询问您现在是否要重新启动并重新连接到代码空间。 如果您想立即更改用于此代码空间的机器类型,请单击 Yes(是) 。 如果您单击 No(否),或者代码空间当前未运行,更改将在代码空间下次重启时生效。

在 Visual Studio Code 中删除代码空间

  1. 在“Codespaces(代码空间)”下,右键点击您要删除的代码空间。
  2. 在下拉菜单中,单击 Delete Codespace(删除代码空间)在 GitHub 中删除代码空间

帮助我们创建出色的文档!

所有 GitHub 文档都是开源的。看到错误或不清楚的内容了吗?提交拉取请求。

做出贡献

或, 了解如何参与。