> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/zh/getting-started/git-sync/monorepos.md).

# 单体仓库

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 上创建三个部分，并为它们配置不同的项目目录：

* `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` ，同步将使用该目录范围内的默认配置。

### 多部分仓库中目录和资源的工作方式

每个已同步的部分都有自己的 **项目目录**。GitBook 会从已配置的项目目录中读取该部分的 `.gitbook.yaml` 。然后它会解析 `root`, `README.md`, `SUMMARY.md`、Markdown 文件以及该部分同步范围内的资源路径。

在 monorepo 中，每个已同步的部分都限定在自己的目录和文件范围内。从另一个目录同步的不同部分不会自动继承或重用仓库中其他位置的文件。

资源也遵循同样的规则。仓库级别的 `.gitbook/assets` 文件夹不会在不同部分之间自动共享，即使这些部分使用不同的项目目录也是如此。

如果多个部分需要相同的文件，请使用以下模式之一：

* 将资源放在每个部分的目录中。
* 重新组织仓库，使每个部分的同步范围包含其引用的资源。

当你在 monorepo 中设置一个新部分时，请先在仓库中创建你想要的目录结构。GitBook 不会为你推断共享的多部分布局，也不会创建共享资源区域。

有关如何 `root` 在某个部分的同步范围内解析的更多细节，请参见 [内容配置](/docs/documentation/zh/getting-started/git-sync/content-configuration.md#root).

下面是一个具体示例：

```
/
  packages/
    docs-en/
      .gitbook.yaml
      README.md
      SUMMARY.md
      .gitbook/
        assets/
          logo.png
    docs-fr/
      .gitbook.yaml
      README.md
      SUMMARY.md
      .gitbook/
        assets/
          logo.png
```

在这个仓库中， `packages/docs-en` 和 `packages/docs-fr` 是两个独立的已同步部分。来自 `packages/docs-en/.gitbook/assets/logo.png` 的文件不会自动提供给从 `packages/docs-fr`.

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

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

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

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

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

GitBook 期望该部分的所有与 GitBook 相关的文件都位于已配置的项目目录中。这包括 Markdown 文件、 `README.md`, `SUMMARY.md`以及该部分使用的任何资源。

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

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

我们建议下一步操作是一次提交，将仓库中所有与 GitBook 相关的文件（markdown 文件、README/SUMMARY 以及资源）移动到项目目录中的正确新位置。如果资源仍然位于新的项目目录之外，就不要指望它们能在该部分中解析。

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

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
