> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Gitea 同步

> 关联你的 Gitea 账户，导入或导出项目，双向同步更改，以及取消关联。

将项目连接到 Gitea 仓库。更改双向同步，并且只在你点击 **Sync** 时进行：不会自动同步任何内容。

> [!NOTE]
>
> 管理员需要先启用 [Gitea 同步](https://ayakaleaf-pro.mintlify.site/zh-CN/on-premises/configuration/overleaf-toolkit/integrations/gitea-synchronisation.md)。

## 关联你的 Gitea 账户

这只需要做一次。

**1. 打开账户设置**

点击 **Account**，然后点击 **Account settings**。在 **Project synchronisation** 下找到 **Gitea**，点击 **Link**。

![账户设置中的 Gitea 部分，带有 Link 按钮](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-link.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=5514bcd66b524c3dde2376db09935feb)

账户设置中的 Gitea

**2. 在 Gitea 上授权**

Gitea 会打开。如有要求请登录，然后授权该应用。

**3. 检查关联**

你会回到账户设置。一条绿色消息提示你的 Gitea 账户已关联，按钮现在显示为 **Unlink**。

![账户设置中的 Gitea 部分，带有 Unlink 按钮](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-linked.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=b0eb94a11ff546a6770d4f5a8b5250de)

你的 Gitea 账户已关联

如果你的账户尚未关联，**Import from Gitea** 和编辑器中的 **Gitea** 卡片会先要求你关联账户。点击 **Link to your Gitea account**。你同样会进入账户设置，如果是从编辑器开始的，则会在新标签页中打开。然后返回并重新开始。

![带有 Link to your Gitea account 按钮的 Import from Gitea 对话框](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-link-prompt.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=b9f6e8fc7d3aa2d3328423f660de5a9c)

账户未关联时的提示

## 导入仓库

这会从 Gitea 仓库创建一个新项目，并且已与该仓库关联。

**1. 打开导入对话框**

在项目页面中，点击 **New project**，然后点击 **Import from Gitea**。

![带有 Import from Gitea 的 New project 菜单](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-new-project-menu.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=de3258081da7ec5af1083ae6c127d510)

New project 菜单

**2. 选择仓库**

点击仓库旁边的 **Import to Overleaf**。列表包含你的仓库以及你所在组织的仓库。空仓库不会列出：它至少需要一个提交。

![列出四个仓库的 Import from Gitea 对话框](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-import.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=9b8c86ed6705efddab590e0e8f62892c)

你的 Gitea 仓库

**3. 检查项目**

新项目会打开，并包含仓库中的文件。

![编辑器显示导入的项目及其文件和编译后的 PDF](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-imported.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=bd72f7c7594e0f80e0966d4691598db3)

导入的项目

## 将项目导出到新仓库

这会从项目创建一个仓库，并将两者关联。项目只能通过这种方式或导入来关联：你无法将它关联到已存在的仓库。

**1. 在编辑器中打开 Gitea**

打开项目。在左侧栏中点击 **Integrations**，然后点击 **Gitea**。

![带有 Gitea 卡片的 Integrations 面板](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-integrations.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=12710e50eecf8f3b385565c85b4a45a4)

Integrations 面板

**2. 填写仓库信息**

选择 **Owner**，可以是你自己，也可以是你所在的某个组织。选择组织时，该字段名为 **Organization**。**Repository Name** 默认为项目名称：如果名称中有空格，请修改，因为 Gitea 不接受空格。描述是可选的，**Private** 默认处于选中状态。点击 **Create a Gitea repository**。

![已填写的 Export Project to Gitea 表单](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-export.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=867cf2d205d151a87dd35529b4e40d56)

Export Project to Gitea

如果名称中有空格或已被占用，对话框会显示 **Please check that the repository name is valid, and that you have permission to create the repository.** 请修改名称，然后再次点击按钮。

**3. 检查关联**

对话框现在显示 **This project is linked to** 以及仓库名称。

![导出后的 Sync with Gitea 对话框](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-exported.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=aa8d526d60f9733ba1885e73621ab8d6)

项目已关联

## 同步

**1. 打开同步对话框**

打开已关联的项目。在左侧栏中点击 **Integrations**，然后点击 **Gitea**。

**Recent commits in Gitea** 列出了将要进入项目的内容。

![列出一个新提交的 Sync with Gitea 对话框](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-new-commits.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=0403560179cb63a6b5d3853f4590e6a5)

Gitea 中有一个新提交在等待

**2. 描述你的更改**

如果你在项目中做了更改，会出现提交信息输入框。它是可选的：如果留空，提交名称为 `Updates from Overleaf`。

![已填写提交信息的 Sync with Gitea 对话框](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-commit-message.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=014cd300d4deff341310920221c63a30)

你的更改的提交信息

**3. 点击 Sync**

点击 **Sync**。来自 Gitea 的新提交会进入项目，你的更改会推送到仓库的默认分支。如果两边修改了不同的内容，系统会通过一个拉取请求为你合并，该拉取请求会作为记录保留在 Gitea 上。

**4. 检查结果**

对话框显示 **No new commits in Gitea since last merge.**，提交信息输入框也消失了。编辑器中的文件和 Gitea 上的提交都已是最新状态。

![同步后没有新提交的 Sync with Gitea 对话框](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-done.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=7a53483772e17e5ad75d5ceb7f44e34e)

一切已同步

### 如果两边修改了相同的行

对话框会提示无法合并更改，并给出一个新分支 `overleaf-YYYY-MM-DD-HHMMSS`，其中保存了你的更改。Overleaf 还会在 Gitea 上从该分支创建一个拉取请求。

![带有合并冲突警告的 Sync with Gitea 对话框](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-conflict.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=9acaf32d0930decd2cfce516037a37b1)

冲突

1. 使用 Git 将该分支合并到默认分支，并解决冲突。在此期间你可以关闭对话框：再次打开时它会显示相同的消息。

   ```bash theme={null}
   git clone <repository-address>
   cd <repository-name>
   git merge origin/overleaf-YYYY-MM-DD-HHMMSS
   # fix the conflict in the file Git names
   git add <file>
   git commit
   git push
   ```
2. 点击 **I have manually merged. Continue**。合并后的结果会进入项目。如果在分支合并之前点击，对话框会保持不变。
3. 该分支会保留在 Gitea 上，其拉取请求也保持打开状态。不再需要时，请关闭拉取请求并删除分支。

当分支保护规则阻止拉取请求时（例如需要审批），即使没有冲突的行，也会出现同样的对话框。一旦规则允许，请在 Gitea 上合并该拉取请求，然后点击 **I have manually merged. Continue**。请参阅[与 Gitea 同步的工作原理](https://ayakaleaf-pro.mintlify.site/zh-CN/on-premises/configuration/overleaf-toolkit/integrations/gitea-synchronisation.md#how-syncing-works-with-gitea)。

## 取消项目关联

当你不再希望项目同步时执行此操作。

**1. 点击 Unlink**

在同步对话框中，点击 **Unlink**。

**2. 确认**

点击 **Confirm**。这只会移除关联：警告中提到的连接到你拥有的仓库，是你之后可以选择的操作，而不是现在就会发生的事情。

![要求确认取消关联的 Sync with Gitea 对话框](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-unlink-project.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=796d5581463a481fed1772d6695430d1)

确认取消关联

**3. 检查结果**

对话框现在显示 **Export Project to Gitea**。项目和仓库都会保留各自的内容。要再次同步，请将项目导出到新仓库，或将仓库导入到新项目。

## 取消关联你的 Gitea 账户

在 **Account settings** 的 **Gitea** 下，点击 **Unlink**，然后在对话框中再次点击 **Unlink**。

![Unlink Gitea Account 对话框](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitea-sync-unlink-account.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=b3995614c688a587c031de666d71ce64)

取消关联你的账户

你的项目仍与各自的仓库保持关联。在你再次关联账户之前，无法同步它们。

> [!NOTE]
>
> 关于共享项目中谁可以做什么，请参阅[谁可以关联和同步](https://ayakaleaf-pro.mintlify.site/zh-CN/on-premises/configuration/overleaf-toolkit/integrations/gitea-synchronisation.md#who-can-link-and-sync)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.