1. 安装repo

新建放置repo的bin目录
$ mkdir ~/bin
$ echo "export PATH=~/bin:\$PATH" >> ~/.bashrc
$ source ~/.bashrc
获取repo并赋予可执行权限(或者参考google官方网站
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

2. 初始化一个repo客户端

创建一个目录用于放置需要下载的源代码
$ mkdir Android
 $ cd Android
运行repo init 初始化一个repo客户端;
获取一个最新的版本则直接指定manifest的URL地址
 $ repo init -u git://192.168.1.183/android/platform/manifest.git

推荐使用(初始化速度更快,要不然会受到https://gerrit.googlesource.com/git-repo连接失败的影响,原因:1.公司内可能https网络限制2.被GFW屏蔽):
 $ repo init -u git://192.168.1.183/android/platform/manifest.git --repo-url=git://192.168.1.183/android/tools/repo.git
获取除了最新版本的其他版本,可以使用"-b"选项
 $ repo init -u git://192.168.1.183/android/platform/manifest.git -b android-4.1.1_r2

推荐使用
(初始化速度更快,要不然会受到https://gerrit.googlesource.com/git-repo连接失败的影响,原因:1.公司内可能https网络限制2.被GFW屏蔽)
$ repo init -u git://192.168.1.183/android/platform/manifest.git -b android-4.1.1_r2 --repo-url=git://192.168.1.183/android/tools/repo.git
目前已经有的branch列表:
 
 * [new branch]      android-1.6_r1 -> origin/android-1.6_r1
 * [new branch]      android-1.6_r1.1 -> origin/android-1.6_r1.1
 * [new branch]      android-1.6_r1.2 -> origin/android-1.6_r1.2
 * [new branch]      android-1.6_r1.3 -> origin/android-1.6_r1.3
 * [new branch]      android-1.6_r1.4 -> origin/android-1.6_r1.4
 * [new branch]      android-1.6_r1.5 -> origin/android-1.6_r1.5
 * [new branch]      android-1.6_r2 -> origin/android-1.6_r2
 * [new branch]      android-2.0.1_r1 -> origin/android-2.0.1_r1
 * [new branch]      android-2.0_r1 -> origin/android-2.0_r1
 * [new branch]      android-2.1_r1 -> origin/android-2.1_r1
 * [new branch]      android-2.1_r2 -> origin/android-2.1_r2
 * [new branch]      android-2.1_r2.1p -> origin/android-2.1_r2.1p
 * [new branch]      android-2.1_r2.1p2 -> origin/android-2.1_r2.1p2
 * [new branch]      android-2.1_r2.1s -> origin/android-2.1_r2.1s
 * [new branch]      android-2.2.1_r1 -> origin/android-2.2.1_r1
 * [new branch]      android-2.2.1_r2 -> origin/android-2.2.1_r2
 * [new branch]      android-2.2.2_r1 -> origin/android-2.2.2_r1
 * [new branch]      android-2.2.3_r1 -> origin/android-2.2.3_r1
 * [new branch]      android-2.2.3_r2 -> origin/android-2.2.3_r2
 * [new branch]      android-2.2.3_r2.1 -> origin/android-2.2.3_r2.1
 * [new branch]      android-2.2_r1 -> origin/android-2.2_r1
 * [new branch]      android-2.2_r1.1 -> origin/android-2.2_r1.1
 * [new branch]      android-2.2_r1.2 -> origin/android-2.2_r1.2
 * [new branch]      android-2.2_r1.3 -> origin/android-2.2_r1.3
 * [new branch]      android-2.3.1_r1 -> origin/android-2.3.1_r1
 * [new branch]      android-2.3.2_r1 -> origin/android-2.3.2_r1
 * [new branch]      android-2.3.3_r1 -> origin/android-2.3.3_r1
 * [new branch]      android-2.3.3_r1.1 -> origin/android-2.3.3_r1.1
 * [new branch]      android-2.3.4_r0.9 -> origin/android-2.3.4_r0.9
 * [new branch]      android-2.3.4_r1 -> origin/android-2.3.4_r1
 * [new branch]      android-2.3.5_r1 -> origin/android-2.3.5_r1
 * [new branch]      android-2.3.6_r0.9 -> origin/android-2.3.6_r0.9
 * [new branch]      android-2.3.6_r1 -> origin/android-2.3.6_r1
 * [new branch]      android-2.3.7_r1 -> origin/android-2.3.7_r1
 * [new branch]      android-2.3_r1 -> origin/android-2.3_r1
 * [new branch]      android-4.0.1_r1 -> origin/android-4.0.1_r1
 * [new branch]      android-4.0.1_r1.1 -> origin/android-4.0.1_r1.1
 * [new branch]      android-4.0.1_r1.2 -> origin/android-4.0.1_r1.2
 * [new branch]      android-4.0.2_r1 -> origin/android-4.0.2_r1
 * [new branch]      android-4.0.3_r1 -> origin/android-4.0.3_r1
 * [new branch]      android-4.0.3_r1.1 -> origin/android-4.0.3_r1.1
 * [new branch]      android-4.0.4_r1 -> origin/android-4.0.4_r1
 * [new branch]      android-4.0.4_r1.1 -> origin/android-4.0.4_r1.1
 * [new branch]      android-4.0.4_r1.2 -> origin/android-4.0.4_r1.2
 * [new branch]      android-4.0.4_r2 -> origin/android-4.0.4_r2
 * [new branch]      android-4.0.4_r2.1 -> origin/android-4.0.4_r2.1
 * [new branch]      android-4.1.1_r1 -> origin/android-4.1.1_r1
 * [new branch]      android-4.1.1_r1.1 -> origin/android-4.1.1_r1.1
 * [new branch]      android-4.1.1_r2 -> origin/android-4.1.1_r2
 * [new branch]      android-4.1.1_r3 -> origin/android-4.1.1_r3
 * [new branch]      android-4.1.1_r4 -> origin/android-4.1.1_r4
 * [new branch]      android-4.1.1_r5 -> origin/android-4.1.1_r5
 * [new branch]      android-4.1.1_r6 -> origin/android-4.1.1_r6
 * [new branch]      android-4.1.1_r6.1 -> origin/android-4.1.1_r6.1
 * [new branch]      android-4.1.2_r1 -> origin/android-4.1.2_r1
 * [new branch]      android-4.1.2_r2 -> origin/android-4.1.2_r2
 * [new branch]      android-4.1.2_r2.1 -> origin/android-4.1.2_r2.1
 * [new branch]      android-4.2.1_r1 -> origin/android-4.2.1_r1
 * [new branch]      android-4.2.1_r1.1 -> origin/android-4.2.1_r1.1
 * [new branch]      android-4.2.1_r1.2 -> origin/android-4.2.1_r1.2
 * [new branch]      android-4.2.2_r1 -> origin/android-4.2.2_r1
 * [new branch]      android-4.2.2_r1.1 -> origin/android-4.2.2_r1.1
 * [new branch]      android-4.2.2_r1.2 -> origin/android-4.2.2_r1.2
 * [new branch]      android-4.2.2_r1.2b -> origin/android-4.2.2_r1.2b
 * [new branch]      android-4.2_r1 -> origin/android-4.2_r1
 * [new branch]      android-4.3.1_r1 -> origin/android-4.3.1_r1
 * [new branch]      android-4.3_r0.9 -> origin/android-4.3_r0.9
 * [new branch]      android-4.3_r0.9.1 -> origin/android-4.3_r0.9.1
 * [new branch]      android-4.3_r1 -> origin/android-4.3_r1
 * [new branch]      android-4.3_r1.1 -> origin/android-4.3_r1.1
 * [new branch]      android-4.3_r2 -> origin/android-4.3_r2
 * [new branch]      android-4.3_r2.1 -> origin/android-4.3_r2.1
 * [new branch]      android-4.3_r2.2 -> origin/android-4.3_r2.2
 * [new branch]      android-4.3_r2.2-cts -> origin/android-4.3_r2.2-cts
 * [new branch]      android-4.3_r2.3 -> origin/android-4.3_r2.3
 * [new branch]      android-4.3_r3 -> origin/android-4.3_r3
 * [new branch]      android-4.3_r3.1 -> origin/android-4.3_r3.1
 * [new branch]      android-4.4.1_r1 -> origin/android-4.4.1_r1
 * [new branch]      android-4.4.2_r1 -> origin/android-4.4.2_r1
 * [new branch]      android-4.4.2_r2 -> origin/android-4.4.2_r2
 * [new branch]      android-4.4_r1 -> origin/android-4.4_r1
 * [new branch]      android-4.4_r1.1 -> origin/android-4.4_r1.1
 * [new branch]      android-4.4_r1.2 -> origin/android-4.4_r1.2
 * [new branch]      android-cts-2.2_r8 -> origin/android-cts-2.2_r8
 * [new branch]      android-cts-2.3_r10 -> origin/android-cts-2.3_r10
 * [new branch]      android-cts-2.3_r11 -> origin/android-cts-2.3_r11
 * [new branch]      android-cts-2.3_r12 -> origin/android-cts-2.3_r12
 * [new branch]      android-cts-4.0.3_r1 -> origin/android-cts-4.0.3_r1
 * [new branch]      android-cts-4.0.3_r2 -> origin/android-cts-4.0.3_r2
 * [new branch]      android-cts-4.0_r1 -> origin/android-cts-4.0_r1
 * [new branch]      android-cts-4.1_r1 -> origin/android-cts-4.1_r1
 * [new branch]      android-cts-4.1_r2 -> origin/android-cts-4.1_r2
 * [new branch]      android-cts-4.1_r4 -> origin/android-cts-4.1_r4
 * [new branch]      android-cts-4.2_r2 -> origin/android-cts-4.2_r2
 * [new branch]      android-cts-verifier-4.0.3_r1 -> origin/android-cts-verifier-4.0.3_r1
 * [new branch]      android-cts-verifier-4.0_r1 -> origin/android-cts-verifier-4.0_r1
 * [new branch]      android-sdk-4.0.3-tools_r1 -> origin/android-sdk-4.0.3-tools_r1
 * [new branch]      android-sdk-4.0.3_r1 -> origin/android-sdk-4.0.3_r1
 * [new branch]      android-sdk-4.4.2_r1 -> origin/android-sdk-4.4.2_r1
 * [new branch]      android-sdk-adt_r16.0.1 -> origin/android-sdk-adt_r16.0.1
 * [new branch]      android-sdk-adt_r20 -> origin/android-sdk-adt_r20
 * [new branch]      android-sdk-support_r11 -> origin/android-sdk-support_r11
 * [new branch]      chromium-dev -> origin/chromium-dev
 * [new branch]      froyo      -> origin/froyo
 * [new branch]      gingerbread -> origin/gingerbread
 * [new branch]      gingerbread-release -> origin/gingerbread-release
 * [new branch]      ics-mr0    -> origin/ics-mr0
 * [new branch]      ics-mr1    -> origin/ics-mr1
 * [new branch]      ics-plus-aosp -> origin/ics-plus-aosp
 * [new branch]      idea133    -> origin/idea133
 * [new branch]      idea133-weekly-release -> origin/idea133-weekly-release
 * [new branch]      jb-dev     -> origin/jb-dev
 * [new branch]      jb-mr1-dev -> origin/jb-mr1-dev
 * [new branch]      jb-mr1-dev-plus-aosp -> origin/jb-mr1-dev-plus-aosp
 * [new branch]      jb-mr1.1-dev -> origin/jb-mr1.1-dev
 * [new branch]      jb-mr1.1-dev-plus-aosp -> origin/jb-mr1.1-dev-plus-aosp
 * [new branch]      jb-mr2-dev -> origin/jb-mr2-dev
 * [new branch]      jumper-stable -> origin/jumper-stable
 * [new branch]      kitkat-cts-dev -> origin/kitkat-cts-dev
 * [new branch]      kitkat-dev -> origin/kitkat-dev
 * [new branch]      master     -> origin/master
 * [new branch]      master-art -> origin/master-art
 * [new branch]      master-art-host -> origin/master-art-host
 * [new branch]      master-dalvik -> origin/master-dalvik
 * [new branch]      master-dalvik-host -> origin/master-dalvik-host
 * [new branch]      tools-canary-release -> origin/tools-canary-release
 * [new branch]      tools_ndk_r9d -> origin/tools_ndk_r9d
 * [new branch]      tools_r20  -> origin/tools_r20
 * [new branch]      tools_r21  -> origin/tools_r21
 * [new branch]      tools_r21.1 -> origin/tools_r21.1
 * [new branch]      tools_r22  -> origin/tools_r22
 * [new branch]      tools_r22.2 -> origin/tools_r22.2
 * [new branch]      tools_r22.6 -> origin/tools_r22.6
 * [new branch]      tradedef   -> origin/tradedef
 * [new branch]      tradefed   -> origin/tradefed
 * [new branch]      ub-tools-idea133 -> origin/ub-tools-idea133
 * [new branch]      ub-tools-idea133-release -> origin/ub-tools-idea133-release
 * [new branch]      ub-tools-master -> origin/ub-tools-master
 * [new tag]         android-1.6_r1.1_ -> android-1.6_r1.1_
 * [new tag]         android-1.6_r1.2_ -> android-1.6_r1.2_
 * [new tag]         android-1.6_r1.3_ -> android-1.6_r1.3_
 * [new tag]         android-1.6_r1.4_ -> android-1.6_r1.4_
 * [new tag]         android-1.6_r1.5_ -> android-1.6_r1.5_
 * [new tag]         android-1.6_r1_ -> android-1.6_r1_
 * [new tag]         android-1.6_r2_ -> android-1.6_r2_
 * [new tag]         android-2.0.1_r1_ -> android-2.0.1_r1_
 * [new tag]         android-2.0_r1_ -> android-2.0_r1_
 * [new tag]         android-2.1_r1_ -> android-2.1_r1_
 * [new tag]         android-2.1_r2.1p2_ -> android-2.1_r2.1p2_
 * [new tag]         android-2.1_r2.1p_ -> android-2.1_r2.1p_
 * [new tag]         android-2.1_r2.1s_ -> android-2.1_r2.1s_
 * [new tag]         android-2.1_r2_ -> android-2.1_r2_
 * [new tag]         android-2.2.1_r1_ -> android-2.2.1_r1_
 * [new tag]         android-2.2.1_r2_ -> android-2.2.1_r2_
 * [new tag]         android-2.2.2_r1_ -> android-2.2.2_r1_
 * [new tag]         android-2.2.3_r1 -> android-2.2.3_r1
 * [new tag]         android-2.2.3_r2 -> android-2.2.3_r2
 * [new tag]         android-2.2.3_r2.1 -> android-2.2.3_r2.1
 * [new tag]         android-2.2_r1.1_ -> android-2.2_r1.1_
 * [new tag]         android-2.2_r1.2_ -> android-2.2_r1.2_
 * [new tag]         android-2.2_r1.3_ -> android-2.2_r1.3_
 * [new tag]         android-2.2_r1_ -> android-2.2_r1_
 * [new tag]         android-2.3.1_r1_ -> android-2.3.1_r1_
 * [new tag]         android-2.3.2_r1_ -> android-2.3.2_r1_
 * [new tag]         android-2.3.3_r1.1_ -> android-2.3.3_r1.1_
 * [new tag]         android-2.3.3_r1_ -> android-2.3.3_r1_
 * [new tag]         android-2.3.4_r0.9_ -> android-2.3.4_r0.9_
 * [new tag]         android-2.3.4_r1_ -> android-2.3.4_r1_
 * [new tag]         android-2.3.5_r1_ -> android-2.3.5_r1_
 * [new tag]         android-2.3.6_r0.9 -> android-2.3.6_r0.9
 * [new tag]         android-2.3.6_r1 -> android-2.3.6_r1
 * [new tag]         android-2.3.7_r1 -> android-2.3.7_r1
 * [new tag]         android-2.3_r1_ -> android-2.3_r1_
 * [new tag]         android-4.0.1_r1 -> android-4.0.1_r1
 * [new tag]         android-4.0.1_r1.1 -> android-4.0.1_r1.1
 * [new tag]         android-4.0.1_r1.2 -> android-4.0.1_r1.2
 * [new tag]         android-4.0.2_r1 -> android-4.0.2_r1
 * [new tag]         android-4.0.3_r1 -> android-4.0.3_r1
 * [new tag]         android-4.0.3_r1.1 -> android-4.0.3_r1.1
 * [new tag]         android-4.0.4_r1 -> android-4.0.4_r1
 * [new tag]         android-4.0.4_r1.1 -> android-4.0.4_r1.1
 * [new tag]         android-4.0.4_r1.2 -> android-4.0.4_r1.2
 * [new tag]         android-4.0.4_r2 -> android-4.0.4_r2
 * [new tag]         android-4.0.4_r2.1 -> android-4.0.4_r2.1
 * [new tag]         android-4.1.1_r1 -> android-4.1.1_r1
 * [new tag]         android-4.1.1_r1.1 -> android-4.1.1_r1.1
 * [new tag]         android-4.1.1_r1_ -> android-4.1.1_r1_
 * [new tag]         android-4.1.1_r2 -> android-4.1.1_r2
 * [new tag]         android-4.1.1_r3 -> android-4.1.1_r3
 * [new tag]         android-4.1.1_r4 -> android-4.1.1_r4
 * [new tag]         android-4.1.1_r5 -> android-4.1.1_r5
 * [new tag]         android-4.1.1_r6 -> android-4.1.1_r6
 * [new tag]         android-4.1.1_r6.1 -> android-4.1.1_r6.1
 * [new tag]         android-4.1.2_r1 -> android-4.1.2_r1
 * [new tag]         android-4.1.2_r2 -> android-4.1.2_r2
 * [new tag]         android-4.1.2_r2.1 -> android-4.1.2_r2.1
 * [new tag]         android-4.2.1_r1 -> android-4.2.1_r1
 * [new tag]         android-4.2.1_r1.1 -> android-4.2.1_r1.1
 * [new tag]         android-4.2.1_r1.2 -> android-4.2.1_r1.2
 * [new tag]         android-4.2.1_r1__ -> android-4.2.1_r1__
 * [new tag]         android-4.2.2_r1.1 -> android-4.2.2_r1.1
 * [new tag]         android-4.2.2_r1.2 -> android-4.2.2_r1.2
 * [new tag]         android-4.2.2_r1_ -> android-4.2.2_r1_
 * [new tag]         android-4.2_r1 -> android-4.2_r1
 * [new tag]         android-4.2_r1_ -> android-4.2_r1_
 * [new tag]         android-4.2_r1___ -> android-4.2_r1___
 * [new tag]         android-4.3.1_r1 -> android-4.3.1_r1
 * [new tag]         android-4.3_r0.9 -> android-4.3_r0.9
 * [new tag]         android-4.3_r0.9.1 -> android-4.3_r0.9.1
 * [new tag]         android-4.3_r0.9.1_ -> android-4.3_r0.9.1_
 * [new tag]         android-4.3_r0.9_ -> android-4.3_r0.9_
 * [new tag]         android-4.3_r1 -> android-4.3_r1
 * [new tag]         android-4.3_r1.1 -> android-4.3_r1.1
 * [new tag]         android-4.3_r1_ -> android-4.3_r1_
 * [new tag]         android-4.3_r2 -> android-4.3_r2
 * [new tag]         android-4.3_r2.1 -> android-4.3_r2.1
 * [new tag]         android-4.3_r2.1_ -> android-4.3_r2.1_
 * [new tag]         android-4.3_r2.1__ -> android-4.3_r2.1__
 * [new tag]         android-4.3_r2.2 -> android-4.3_r2.2
 * [new tag]         android-4.3_r2.3 -> android-4.3_r2.3
 * [new tag]         android-4.3_r2_ -> android-4.3_r2_
 * [new tag]         android-4.3_r3 -> android-4.3_r3
 * [new tag]         android-4.3_r3.1 -> android-4.3_r3.1
 * [new tag]         android-4.4.1_r1 -> android-4.4.1_r1
 * [new tag]         android-4.4.2_r1 -> android-4.4.2_r1
 * [new tag]         android-4.4.2_r2 -> android-4.4.2_r2
 * [new tag]         android-4.4_r1 -> android-4.4_r1
 * [new tag]         android-4.4_r1.1 -> android-4.4_r1.1
 * [new tag]         android-4.4_r1.2 -> android-4.4_r1.2
 * [new tag]         android-cts-2.2_r8 -> android-cts-2.2_r8
 * [new tag]         android-cts-2.3_r10 -> android-cts-2.3_r10
 * [new tag]         android-cts-2.3_r11 -> android-cts-2.3_r11
 * [new tag]         android-cts-2.3_r12 -> android-cts-2.3_r12
 * [new tag]         android-cts-4.0.3_r1 -> android-cts-4.0.3_r1
 * [new tag]         android-cts-4.0.3_r2 -> android-cts-4.0.3_r2
 * [new tag]         android-cts-4.0_r1 -> android-cts-4.0_r1
 * [new tag]         android-cts-4.1_r1 -> android-cts-4.1_r1
 * [new tag]         android-cts-4.1_r2 -> android-cts-4.1_r2
 * [new tag]         android-cts-4.1_r4 -> android-cts-4.1_r4
 * [new tag]         android-cts-4.2_r2 -> android-cts-4.2_r2
 * [new tag]         android-cts-4.4_r1 -> android-cts-4.4_r1
 * [new tag]         android-cts-verifier-4.0.3_r1 -> android-cts-verifier-4.0.3_r1
 * [new tag]         android-cts-verifier-4.0_r1 -> android-cts-verifier-4.0_r1
 * [new tag]         android-sdk-4.0.3-tools_r1 -> android-sdk-4.0.3-tools_r1
 * [new tag]         android-sdk-4.0.3_r1 -> android-sdk-4.0.3_r1
 * [new tag]         android-sdk-4.4.2_r1 -> android-sdk-4.4.2_r1
 * [new tag]         android-sdk-adt_r16.0.1 -> android-sdk-adt_r16.0.1
 * [new tag]         android-sdk-adt_r20 -> android-sdk-adt_r20
 * [new tag]         android-sdk-support_r11 -> android-sdk-support_r11
 
小技巧

可以手动指定repo sync所使用的线程数,默认是4个线程,比如使用8个线程 $ repo sync -j8

3. 下载代码

下载对应branch的代码,不指定branch默认是master的最新代码
 $ repo sync
 最终会出现:
 Fetching projects: 100% (344/344), done.
 Checking out files: 100% (9390/9390), done.out files:  25% (2388/9390)
 Checking out files: 100% (1304/1304), done.out files:  40% (529/1304)
 Checking out files: 100% (24607/24607), done.ut files:  50% (12308/24607)
 Checking out files: 100% (18917/18917), done.ut files:   0% (23/18917)
 Checking out files: 100% (36619/36619), done.ut files:  27% (10042/36619)
 Checking out files: 100% (96/96), done.
 Syncing work tree: 100% (344/344), done.
 表示repo sync 运行成功,如果失败请再次执行repo sync,repo会续传,继续下载代码。
小技巧
可以手动指定repo sync所使用的线程数,比如使用8个线程
 $ repo sync -j8

4. 实际测试数据

下载代码大小:~16GB
时间:8m44.147s
real    8m44.147s(表示用户实际使用时间)
user    10m20.180s
sys     2m9.600s

 

转载于:https://www.cnblogs.com/GMCisMarkdownCraftsman/archive/2012/12/04/3751792.html

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐