跳至主要内容

删除 Codespace

您可以删除不再需要的 Codespace。

概述

停止后且保持非活动状态一定天数后,GitHub Codespaces 会自动删除。每个 Codespace 的保留期在创建 Codespace 时设置,并且不会更改。默认保留期为 30 天。请参阅“配置 Codespaces 的自动删除”。

您可以通过多种方式手动删除 Codespace

  • 使用 GitHub CLI 在终端中
  • 在 Visual Studio Code 中
  • 在您的网络浏览器中

使用本文顶部的选项卡显示删除 Codespace 的每种方法的说明。

注意

您无法从 JetBrains Gateway、JetBrains 客户端应用程序或 JupyterLab 中删除 Codespace。

为什么要删除未使用的 Codespaces

存储 Codespaces 会产生费用。因此,您应删除不再需要的任何 Codespaces。请参阅“关于 GitHub Codespaces 的计费”。

您可以创建的 Codespaces 数量以及可以同时运行的 Codespaces 数量有限制。这些限制会根据多种因素而有所不同。如果您达到 Codespaces 的最大数量并尝试创建另一个 Codespace,则会显示一条消息,告知您必须先删除现有 Codespace,然后才能创建新的 Codespace。

删除 Codespace

  1. 在 GitHub 的左上角,选择,然后单击 **Codespaces** 以转到 github.com/codespaces 上的“您的 Codespaces”页面。

  2. 在要删除的 Codespace 的右侧,单击,然后单击 ** 删除**。

    Screenshot of a list of codespaces with the dropdown menu for one of them displayed, showing the "Delete" option.

注意

您可能有一些预构建的 Codespaces 正在占用额外的存储空间,而这些空间未在此仪表板上显示。要删除它们,请按照“删除预构建配置”中的步骤操作。

当您当前未在 Codespace 中工作时,您可以在 VS Code 中删除 Codespaces。

  1. 在 VS Code 中,在活动栏中,单击“远程资源管理器”图标。

    Screenshot of the Activity Bar. The icon for the "Remote Explorer" side bar (a rectangle overlaid by a circle) is highlighted with an orange outline.

    注意

    如果活动栏中未显示“远程资源管理器”

    1. 访问命令面板。例如,按 Shift+Command+P(Mac)/ Ctrl+Shift+P(Windows/Linux)。
    2. 输入:details
    3. 单击Codespaces:详细信息
  2. 在“GitHub Codespaces”下,右键单击要删除的 Codespace。

  3. 单击删除 Codespace

要了解有关 GitHub CLI 的更多信息,请参阅“关于 GitHub CLI”。

要删除 Codespace,请使用gh codespace delete 子命令,然后从显示的列表中选择一个 Codespace。

gh codespace delete

如果您有未保存的更改,系统会提示您确认删除。您可以使用--force标志强制删除,从而避免此提示。

有关此命令的更多信息,请参阅GitHub CLI 手册

批量删除 Codespaces

您可以使用 GitHub CLI 通过单个命令删除多个或所有 Codespaces。有关更多信息,请单击此页面顶部的“GitHub CLI”选项卡。

您可以使用 GitHub CLI 通过单个命令删除多个或所有 Codespaces。有关更多信息,请单击此页面顶部的“GitHub CLI”选项卡。

您可以使用单个命令删除多个或所有 Codespaces,方法是使用gh codespace delete,后跟以下标志之一:

--all - 删除所有 Codespaces。

--repo REPOSITORY - 删除此存储库的所有 Codespaces。或者与--days标志一起使用以按 Codespace 的使用期限进行筛选。

--days NUMBER - 删除所有超过指定天数的 Codespaces。可以与--repo标志一起使用。

默认情况下,系统会提示您确认删除任何包含未保存更改的 Codespaces。您可以使用--force标志跳过此确认。

示例

删除您 7 天前为octo-org/octo-repo存储库创建的所有 Codespaces。

gh codespace delete --repo octo-org/octo-repo --days 7

删除组织中的 Codespaces

作为组织所有者,您可以使用 GitHub CLI 删除组织中的任何 Codespace。

有关更多信息,请单击此页面顶部的“GitHub CLI”选项卡。

有关更多信息,请单击此页面顶部的“GitHub CLI”选项卡。

  1. 输入以下命令之一以显示 Codespaces 列表。

    • gh codespace delete --org ORGANIZATION - 列出指定组织中的当前 Codespaces。
    • gh codespace delete --org ORGANIZATION --user USER - 只列出由指定用户创建的 Codespaces。您必须是指定组织的所有者。
  2. 在 Codespaces 列表中,导航到要删除的 Codespace。

  3. 要删除选定的 Codespace,请按 Enter

    如果 Codespace 包含未保存的更改,系统会提示您确认删除。

您也可以使用 REST API 删除组织的 Codespaces。请参阅“Codespaces 组织的 REST API 端点”。

进一步阅读