# 关于锁定的存储库

可以锁定存储库以防止更改，通常为了进行迁移。

## 关于锁定的存储库

将存储库迁移到或从 GitHub 产品时，源和目标存储库可能会被“锁定”用于迁移。 当存储库锁定时，无法对该存储库进行任何更改，例如推送提交、创建问题或对拉取请求进行注释。

迁移期间是否锁定存储库取决于所使用的工具，以及运行迁移时选择的选项。 锁定存储库后，存储库页面上 GitHub会显示包含以下文本的横幅：

> 当前正在迁移此存储库。 进行迁移时，该存储库处于锁定状态。

除了迁移之外，站点管理员还可以出于其他原因锁定存储库。

通常，迁移完成后，存储库会自动解锁。 在其他情况下，解锁存储库是一个手动步骤，解锁存储库所需的过程取决于所使用的迁移工具。

## 通过 GitHub Enterprise Importer 锁定的存储库

迁移正在进行时，目标存储库的访问被锁定。GitHub Enterprise Importer 如果迁移成功完成，存储库将自动解锁。 但是，如果迁移时出现问题（包括迁移失败），存储库可能会保持锁定状态。

GitHub Enterprise Importer 默认情况下不会锁定源存储库。 仅当您在`--lock-source-repo`中指定GitHub CLI选项，或在 GraphQL mutation 的`lockSource`中指定`startRepositoryMigration`属性时，源存储库才会被锁定。

> \[!NOTE]
> 除非确定以后不会解锁源存储库，否则不建议锁定这些存储库。 请考虑改为对存储库进行存档。 有关详细信息，请参阅“[存档仓库](/zh/enterprise-server@3.22/repositories/archiving-a-github-repository/archiving-repositories)”。

有关如何解锁锁定 GitHub Enterprise Importer的存储库的信息，请参阅 [使用 GitHub Enterprise Importer 排查迁移中的问题](/zh/enterprise-server@3.22/migrations/troubleshooting/troubleshooting-your-migration-with-github-enterprise-importer#locked-repositories)。

## 由 Enterprise Live Migrations 归档的存储库

在最新的 GitHub Enterprise Server 版本中，Enterprise Live Migrations 会将源代码仓库归档，而不是锁定。 这样，存储库就可供读取操作使用。

如果在源存储库已归档后切换失败，ELM 服务将尝试取消归档该存储库。 如果此操作失败，存储库管理员可以取消存储库的存档。 请参阅“[存档仓库](/zh/enterprise-server@3.22/repositories/archiving-a-github-repository/archiving-repositories#unarchiving-a-repository)”。

请注意，取消存档存储库将导致实例上的额外负载，因为存储库中的所有问题和拉取请求都将在 Elasticsearch 中重新编制索引。

源存储库取消存档后，您可以使用 `elm migration cutover-to-destination --migration-id MIGRATION-ID` 重试切换，或者使用 `elm migration cancel --migration-id MIGRATION-ID` 中止迁移，并在准备就绪后开始新的迁移。

## 通过“组织迁移”REST API 锁定的存储库

调用[开始组织迁移](/zh/enterprise-server@3.22/rest/migrations/orgs#start-an-organization-migration)终结点以生成源存储库的迁移存档时，默认情况下不会锁定该存储库。 仅当将 `lock_repositories` 参数设置为 `true` 时，才会锁定存储库。

如果通过此终结点锁定存储库，则可以使用[解锁组织存储库](/zh/enterprise-server@3.22/rest/migrations/orgs#unlock-an-organization-repository)终结点解锁存储库。

如果存储库存储在该存储库上 GitHub Enterprise Server，则站点管理员还可以使用站点管理员仪表板解锁存储库。 有关详细信息，请参阅 [锁定存储库](/zh/enterprise-server@3.22/admin/managing-accounts-and-repositories/managing-repositories-in-your-enterprise/locking-a-repository)。

## 通过 `ghe-migrator` 锁定的存储库

使用 `ghe-migrator`时，目标存储库默认处于锁定状态 GitHub Enterprise Server ，并且不会自动解锁。

如果导入成功，可以使用 `ghe-migrator unlock` 命令解锁存储库。 有关详细信息，请参阅“[将数据迁移到 GitHub Enterprise Server](/zh/enterprise-server@3.22/migrations/using-ghe-migrator/migrating-data-to-github-enterprise-server#unlocking-repositories-on-the-target-instance)”。

如果导入失败，则并非所有数据都已迁移，建议删除存储库并重试迁移，以防止数据丢失。

如果确定要使用存储库，站点管理员可以使用站点管理员仪表板解锁存储库。 有关详细信息，请参阅 [锁定存储库](/zh/enterprise-server@3.22/admin/managing-accounts-and-repositories/managing-repositories-in-your-enterprise/locking-a-repository)。

默认情况下，源存储库不会被锁定，只有在使用 `--lock` 命令准备导出存储库时指定了 `ghe-migrator add` 参数的情况下，才会锁定。 若要解锁存储库，请使用 `ghe-migrator unlock` 命令。 有关详细信息，请参阅“[将数据迁移到 GitHub Enterprise Server](/zh/enterprise-server@3.22/migrations/using-ghe-migrator/migrating-data-to-github-enterprise-server#unlocking-repositories-on-the-source)”。

## 通过 `startImport` GraphQL 变更锁定的存储库

使用 `startImport` GraphQL 变更时，目标存储库默认处于锁定状态，并且不会自动解锁。

如果导入成功，可以使用 `unlockImportedRepositories` GraphQL 变更来解锁存储库。 如需文档，请联系你的专家服务或 GitHub 合作伙伴代表。

如果导入失败，则无法自行解锁存储库。 由于迁移失败意味着并非所有数据都已迁移，因此建议删除存储库并重试迁移，以防止数据丢失。

如果确定要解锁存储库，请联系 。