[Git] 用 repo 來管理多個 Repository

雖然很久之前就因為下載 Google Android Source Code,因此使用 repo 來下載及管理多個 Git Repository,雖然對這個方便的 tool 很好奇,但一直沒有去多加探究。而且可惜的是,在網路上的資料,多半只提到如何使用 repo 來下載 Android Open Source Project (AOSP)  的 source code 及 upload change,卻沒有提及如何利用這個 tool 來管理多個 Repository。這邊透過網路上零星的資訊及參考 AOSP 的作法,整理在下面供其他有興趣的人參考。

這邊我利用 github 來做操作範例,各位也可以自行到我的 Picker’s github 去參考看看細節,接下來我們來看看,要同時能夠管理多個 Repository,需要做些什麼事情。


Step 1: Create a new repository for storing the projects’ configuration
首先,各位需要在 github 建立一個 repository,這個 repository 會包含一個 default.xml,用來定義 repo tool 需要取得 repository 的 path 及其 revision 等資訊。這個檔案非常重要,repo 唯有透過這個檔案才能知道它該做什麼事情。
Step 2: Configure your default.xml
記得先將這個專案複製到本地端,然後增加一個 default.xml 檔案。default.xml檔案的格式如下,
<manifest>
    <remote fetch=“[Server site of Repositories]”
                  name=“[You can define any name.]”>
    <default remote=“[The default server you want to use]”
                  revision=“[Path of the revision definition]”
                  sync-j=“[Number of the sync threads]”>
    <project name=“[Path of the repository]”
                   path=“[The folder name that is created to store the project source]”>
</manifest>

下面是實際的範例,

<manifest>
    <remote fetch=“https://github.com” name=”picker”>
    <default remote=“picker” revision=“refs/heads/master” sync-j=“4”>

    <project name=“pickerweng/SystemProperty” path=“SystemProperty”>
    <project name=“pickerweng/CPU-Usage” path=“CPU-Usage” revision=“refs/heads/develop”>
    <project name=“pickerweng/CameraRecorder” path=“CameraRecorder”>
    <project name=“pickerweng/QNotepad” path=“QNotepad”>
</manifest>

Step 3: Use the repo tool to download the multiple projects
在command-line下使用 repo,用法就像在下載 Android source code 一樣簡單,以我的例子來看,先去我的 github 網站上,找到 manifest 這個 repository,然後複製它的下載網址後,丟給 repo 做初始化,等待初始化完成後,變可以同步所有的 repository 了。
以下就是簡單的兩行範例敘述。

    $> repo init -u https://github.com/pickerweng/manifest.git
    $> repo sync

參考資訊:
1. Android Open Source Project
2. wroberts3 – Using Google’s repo command in your own projects
3. 小春 – android 建立local repo server

發佈留言