Repo 的使用小結

1、安裝

建立目錄和修改環境變量python

$ mkdir ~/bin
$ PATH=~/bin:$PATH

下載repo代碼android

$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

2、幫助

repo help

查詢具體命令的幫助git

repo help <COMMAND>

Repo 倉庫狀態api

repo help init

狀態安全

repo status .

3、初始化

$ repo init -u <URL> [<OPTIONS>]

示例服務器

$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY

repo init -u https://android.googlesource.com/platform/manifest

這個命令會在當前文件夾建立一個 .repo 文件夾,它包含curl

1.png

repo/ : 實際上是一個repo的python源碼
manifest.xml : 工做樹的主配置文件,不要編輯這個文件
projects/ : 每一個git工程的 .git結構
local_manifest.xml : 這個文件不是repo建立的,你能夠建立這個文件來代替主配置文件,也就是臨時測試用用ide

選項:測試

-u: 指定manifest倉庫地址
-m: 選擇倉庫中某個manifest文件,若是沒有設置,就使用default.xml
-b: 指定一個分支或修正版本fetch

4、拉代碼

repo sync

repo sync PROJECT0 PROJECT1 PROJECT2 ...

選項:
-j : 多任務,通常8核心能夠開到16任務,過多會起副作用
-c: 只下載當前分支代碼
-d: 讓工程回退到manifest指定的版本
-f: 若是某個工程同步失敗,繼續同步

5、修改repo

若是你想修改repo的結構,應該在 .repo/manifests 文件夾裏面修改,而後用git命令提交

manifest.xml 文件結構:

<?xml version="1.0" encoding="UTF-8"?>  
<manifest>  

  <remote  name="shift"  
           fetch="git://git.mygit.com/" />  
  <default revision="kk-shift"  
           remote="shift"  
           sync-j="1" />  

  <project path="packages/shift/VideoPlayer" name="platform/packages/shift/VideoPlayer" />  
  <include name="another_manifest.xml" />
</manifest>
  1. manifest
    這個是配置的頂層元素,即根標誌

  2. remote
    name:在每個.git/config文件的remote項中用到這個name,即表示每一個git的遠程服務器的名字(這個名字很關鍵,若是多個remote屬性的話,default屬性中須要指定default remote)。git pull、get fetch的時候會用到這個remote name。
    alias :能夠覆蓋以前定義的remote name,name必須是固定的,可是alias能夠不一樣,能夠用來指向不一樣的remote url
    fetch :全部git url真正路徑的前綴,全部git 的project name加上這個前綴,就是git url的真正路徑
    review :指定Gerrit的服務器名,用於repo upload操做。若是沒有指定,則repo upload沒有效果

  3. default
    設定全部projects的默認屬性值,若是在project元素裏沒有指定一個屬性,則使用default元素的屬性值。
    remote :遠程服務器的名字(上面remote屬性中提到過,多個remote的時候須要指定default remote,就是這裏設置了)
    revision :全部git的默認branch,後面project沒有特殊指出revision的話,就用這個branch
    sync_j : 在repo sync中默認並行的數目
    sync_c :若是設置爲true,則只同步指定的分支(revision 屬性指定),而不是全部的ref內容
    sync_s : 若是設置爲true,則會同步git的子項目

  4. manifest-server
    它的url屬性用於指定manifest服務的URL,一般是一個XML RPC 服務
    它要支持一下RPC方法:
    GetApprovedManifest(branch, target) :返回一個manifest用於指示全部projects的分支和編譯目標。
    target參數來自環境變量TARGET_PRODUCT和TARGET_BUILD_VARIANT,組成$TARGET_PRODUCT-$TARGET_BUILD_VARIANT
    GetManifest(tag) :返回指定tag的manifest

  5. project
    須要clone的單獨git
    name :git 的名稱,用於生成git url。URL格式是:${remote fetch}/${project name}.git 其中的 fetch就是上面提到的remote 中的fetch元素,name 就是此處的name
    path :clone到本地的git的工做目錄,若是沒有配置的話,跟name同樣
    remote :定義remote name,若是沒有定義的話就用default中定義的remote name
    revision :指定須要獲取的git提交點,能夠定義成固定的branch,或者是明確的commit 哈希值
    groups :列出project所屬的組,以空格或者逗號分隔多個組名。全部的project都自動屬於"all"組。每個project自動屬於
    name:'name' 和path:'path'組。例如 ,它自動屬於default, name:monkeys, and path:barrel-of組。若是一個project屬於notdefault組,則,repo sync時不會下載
    sync_c :若是設置爲true,則只同步指定的分支(revision 屬性指定),而不是全部的ref內容。
    sync_s : 若是設置爲true,則會同步git的子項目
    upstream :在哪一個git分支能夠找到一個SHA1。用於同步revision鎖定的manifest(-c 模式)。該模式能夠避免同步整個ref空間
    annotation :能夠有0個或多個annotation,格式是name-value,repo forall命令是會用來定義環境變量

  6. include
    經過name屬性能夠引入另一個manifest文件(路徑相對與當前的manifest.xml 的路徑)
    name :另外一個須要導入的manifest文件名字
    能夠在當前的路徑下添加一個another_manifest.xml,這樣能夠在另外一個xml中添加或刪除project

  7. remove-project
    從內部的manifest表中刪除指定的project。常常用於本地的manifest文件,用戶能夠替換一個project的定義

6、建立快照

你能夠根據當前.repo的狀態來建立一個配置文件

repo manifest -o snapshot.xml -r

這個文件能夠用來保存當前的工做狀態

恢復一個快照,能夠用下面的命令

cp snapshot.xml .repo/manifests/
repo init -m snapshot.xml
repo sync -d

注意:沒有commit的修改不會恢復,已經commit的可是沒有push的是能夠恢復的,但只能從本地恢復。

7、切換分支

repo start BRANCH_NAME PROJECT_NAME

查看分支

repo branches

提交

repo upload

安全刪除不須要的分支

repo prune

8、基本工做流程

repo start 開始一個新的工做分支Use to start a new topic branch.
git commit提交修改Use git add to stage changes.
repo upload上傳修改

2

9、一些問題

若是repo長時間沒有響應,能夠試試殺掉python進程

killall python

若是想要repo執行時的更多信息,能夠加上 --trace 選項

參考1.http://xda-university.com/as-a-developer/repo-tips-tricks 參考2.https://source.android.com/source/using-repo 參考3.https://source.android.com/source/developing 參考4.http://blog.csdn.net/shift_wwx/article/details/19557031

相關文章
相關標籤/搜索