> ## 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.

# GitLab 同步

> 連結您的 GitLab 帳號、匯入或匯出專案、雙向同步變更，以及解除連結。

將專案連接至 GitLab 儲存庫。變更會雙向同步，而且只會在您點選 **Sync** 時進行：不會自動同步任何內容。

> [!NOTE]
>
> 管理員必須先啟用 [GitLab 同步](https://ayakaleaf-pro.mintlify.site/zh-TW/on-premises/configuration/overleaf-toolkit/integrations/gitlab-synchronisation.md)。

## 連結您的 GitLab 帳號

這只需要做一次。

**1. 開啟帳號設定**

點選 **Account**，然後點選 **Account settings**。在 **Project synchronisation** 下找到 **GitLab**，點選 **Link**。

![帳號設定中的 GitLab 區段，含有 Link 按鈕](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-link.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=cd34b300ea3566a7083df441f465a163)

帳號設定中的 GitLab

**2. 在 GitLab 上授權**

GitLab 會開啟。如有要求請登入，然後授權該應用程式。

**3. 檢查連結**

您會回到帳號設定。一則綠色訊息表示您的 GitLab 帳號已連結，按鈕現在顯示為 **Unlink**。

![帳號設定中的 GitLab 區段，含有 Unlink 按鈕](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-linked.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=f187b1d6ba770789495f03ecac75c7f7)

您的 GitLab 帳號已連結

如果您的帳號尚未連結，**Import from GitLab** 與編輯器中的 **GitLab** 卡片會先要求您連結帳號。點選 **Link to your GitLab account**。您同樣會進入帳號設定，如果是從編輯器開始，則會在新分頁中開啟。然後返回並重新開始。

![含有 Link to your GitLab account 按鈕的 Import from GitLab 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-link-prompt.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=50ded943f918001121d5a00ef345d008)

帳號未連結時的提示

## 匯入儲存庫

這會從 GitLab 儲存庫建立新專案，並且已與該儲存庫連結。

**1. 開啟匯入對話方塊**

在專案頁面中，點選 **New project**，然後點選 **Import from GitLab**。

![含有 Import from GitLab 的 New project 選單](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-new-project-menu.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=4065d1b3b3e2fc5542272e38e2d01f61)

New project 選單

**2. 選擇儲存庫**

點選儲存庫旁的 **Import to Overleaf**。清單包含您的儲存庫以及您所屬群組的儲存庫。

![列出四個儲存庫的 Import from GitLab 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-import.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=cb0ba36bfa954e101ec1ccd8dac0bca3)

您的 GitLab 儲存庫

**3. 檢查專案**

新專案會開啟，並包含儲存庫中的檔案。

![編輯器顯示匯入的專案及其檔案與編譯後的 PDF](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-imported.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=a467df37fd623dffe523b5a92ebc47c1)

匯入的專案

## 將專案匯出至新的儲存庫

這會從專案建立儲存庫，並將兩者連結。專案只能透過這種方式或匯入來連結：您無法將它連結至已存在的儲存庫。

**1. 在編輯器中開啟 GitLab**

開啟專案。在左側欄中點選 **Integrations**，然後點選 **GitLab**。

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

Integrations 面板

**2. 填寫儲存庫資訊**

選擇 **Owner**，可以是您自己，也可以是您所屬的某個群組。選擇群組時，此欄位名稱為 **Organization**。**Repository Name** 預設為專案名稱。描述為選填，**Private** 預設為已選取。點選 **Create a GitLab repository**。

![已填寫的 Export Project to GitLab 表單](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-export.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=ba5191a105be584e994ad663565ee511)

Export Project to GitLab

如果名稱已被使用，對話方塊會顯示 **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 GitLab 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-exported.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=6e18dc3c00fb9a29b3bb2f1a76cec08e)

專案已連結

## 同步

**1. 開啟同步對話方塊**

開啟已連結的專案。在左側欄中點選 **Integrations**，然後點選 **GitLab**。

**Recent commits in GitLab** 會列出即將進入專案的內容。

![列出一個新提交的 Sync with GitLab 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-new-commits.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=e67529c0cad7a0cb7eafaa5f8d134b0a)

GitLab 中有一個新提交在等待

**2. 描述您的變更**

如果您在專案中做了變更，會出現提交訊息欄位。此欄位為選填：如果留空，提交名稱為 `Updates from Overleaf`。

![已填寫提交訊息的 Sync with GitLab 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-commit-message.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=45677a6ea3a96235bcde72e1cdaa436a)

您的變更的提交訊息

**3. 點選 Sync**

點選 **Sync**。來自 GitLab 的新提交會進入專案，您的變更會推送至儲存庫的預設分支。如果兩邊修改了不同的內容，系統會為您合併。

**4. 檢查結果**

對話方塊顯示 **No new commits in GitLab since last merge.**，提交訊息欄位也消失了。編輯器中的檔案與 GitLab 上的提交都已是最新狀態。

![同步後沒有新提交的 Sync with GitLab 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-done.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=74dd7ceacb36ac0289d76504e95e7ba7)

一切皆已同步

### 如果兩邊修改了相同的行

對話方塊會提示無法合併變更，並指出一個新分支 `overleaf-YYYY-MM-DD-HHMMSS`，其中保存了您的變更。Overleaf 也會在 GitLab 上從該分支開啟一個合併請求。

![含有合併衝突警告的 Sync with GitLab 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-conflict.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=da33555666132affd667ce24b61221c9)

衝突

1. 在 GitLab 上或使用 Git 將該分支合併至預設分支。在此期間您可以關閉對話方塊：再次開啟時會顯示相同的訊息。
2. 點選 **I have manually merged. Continue**。合併後的結果會進入專案。如果在分支合併之前點選，對話方塊會維持不變。
3. 該分支會保留在 GitLab 上，除非您在合併時刪除了它。不再需要時請將其刪除。

當儲存庫的合併規則擋下合併請求時（例如需要核准），即使沒有衝突的行，也會出現相同的對話方塊。一旦規則允許，請在 GitLab 上合併該合併請求，然後點選 **I have manually merged. Continue**。請參閱[與 GitLab 同步的運作方式](https://ayakaleaf-pro.mintlify.site/zh-TW/on-premises/configuration/overleaf-toolkit/integrations/gitlab-synchronisation.md#how-syncing-works-with-gitlab)。

## 解除專案連結

當您不再希望專案同步時執行此操作。

**1. 點選 Unlink**

在同步對話方塊中，點選 **Unlink**。

**2. 確認**

點選 **Confirm**。這只會移除連結：警告中提到的連接至您擁有的儲存庫，是您之後可以選擇的操作，而不是現在就會發生的事。

![要求確認解除連結的 Sync with GitLab 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-unlink-project.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=8d7469fda58abd012ed1364f9f54005d)

確認解除連結

**3. 檢查結果**

對話方塊現在顯示 **Export Project to GitLab**。專案與儲存庫都會保留各自的內容。若要再次同步，請將專案匯出至新的儲存庫，或將儲存庫匯入為新專案。

## 解除您的 GitLab 帳號連結

在 **Account settings** 的 **GitLab** 下，點選 **Unlink**，然後在對話方塊中再次點選 **Unlink**。

![Unlink GitLab Account 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/gitlab-sync-unlink-account.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=478ab26a1f13d3a9cb08ffc15ad64bc1)

解除您的帳號連結

您的專案仍與各自的儲存庫保持連結。在您再次連結帳號之前，無法同步它們。

> [!NOTE]
>
> 關於共用專案中誰可以做什麼，請參閱[誰可以連結與同步](https://ayakaleaf-pro.mintlify.site/zh-TW/on-premises/configuration/overleaf-toolkit/integrations/gitlab-synchronisation.md#who-can-link-and-sync)。


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