# 单体仓库

GitBook 支持 monorepo。monorepo 是一个包含多个逻辑项目的仓库（例如，一个 iOS 客户端和一个 Web 应用）。

GitBook 可以将同一仓库中的多个目录与多个空间同步。在空间中启用 Git Sync 时，你可以配置“项目目录”。它将用于查找 `.gitbook.yaml` 用于与此空间同步的目录的文件。

仓库结构示例：

```
/
  package.json
  packages/
     styleguide/
        .gitbook.yaml
        README.md
        SUMMARY.md
     app/
        README.md
        SUMMARY.md
     api/
        .gitbook.yaml
        README.md
        SUMMARY.md
```

在这个示例中，可以在 GitBook 上创建 3 个空间，并将它们配置为不同的根目录：

* `packages/styleguide`
* `packages/app`
* `packages/api`

Git Sync 级别的“项目目录”选项不同于 [`root` 选项](/docs/documentation/zh/getting-started/git-sync/content-configuration.md#root) 于 `.gitbook.yaml` 配置文件。前者用于查找 `.gitbook.yaml` 本身，然后两者会结合起来查找该目录中的其余文件。如果在“项目目录”中不存在 `.gitbook.yaml` ，同步将使用作用于该目录的默认配置。

## 更新项目目录 <a href="#updating" id="updating"></a>

{% hint style="info" %}
在大多数情况下，我们建议按以下步骤更新项目目录：

1. 禁用现有的 Git Sync
2. 将 Git 仓库中的文件移动到项目目录
3. 使用新的项目目录重新配置 Git Sync
   {% endhint %}

在某些情况下，你可能最初使用的是一个只与一个空间同步的普通仓库，但后来决定将其迁移为一个与多个空间同步的 monorepo；或者可能需要重命名项目目录。

更改现有 Git Sync 的项目目录可能会对内容产生意外影响，该更改只会在下一次同步时传播（在 GitBook 中进行的编辑或 Git 仓库中的新提交）。

#### **如果下一步操作是从 Git 仓库导入**:

GitBook 会预期在项目目录中找到页面和文件。如果这些文件尚未移动到仓库的项目目录中，同步结果将是一个没有任何内容的空空间。

我们建议下一步操作是提交，将所有与 GitBook 相关的文件（markdown 文件、README/SUMMARY 以及资源文件）移动到仓库中的正确新位置，即项目目录。

**如果下一步操作是从 GitBook 导出到 Git 仓库**:

GitBook 将在新的项目目录中生成或更新新文件。与 GitBook 同步的文件将被移动到新的项目目录（尽最大努力）；如果系统的其他部分依赖这些文件，这可能会导致副作用。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.com/docs/documentation/zh/getting-started/git-sync/monorepos.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
