1. 搭建 git 服务器
git服务器有很多,比如使用android 提供的 gerrit 服务器,安装方法参见 gerrit 环境搭建
2 同步远程库
$ mkdir ~/review_site/git/google
$ cd ~/review_site/git/google
$ repo init -u https://android.googlesource.com/platform/manifest
$ head -n 12 .repo/manifest.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="aosp"
fetch="https://android.googlesource.com/"
review="https://android-review.googlesource.com/" />
<default revision="master"
remote="aosp"
sync-j="4" />
<project path="build" name="platform/build" groups="pdk" >
<copyfile src="core/root.mk" dest="Makefile" />
$ repo sync
直接同步(sync)会出现”代码库不存在“错误,是因为使用的repo不支持manifest相对路径。
如果从 http://android.git.kernel.org/repo 下载 repo 就会有这个问题,建议从 https://chromium.googlesource.com/external/repo 下载
需要参照上面修改 .repo/manifest.xml 文件中的 fetch 节点,然后再同步。
3 调整代码库
如果需要对 android 进行二次开发,最好创建自己的分支,方法如下:
3.1 所有项目增加分支
直接在代码库中执行
$ repo forall -c git branch --no-track mybranch master
3.2 manifest 项目增加相应分支
- 首先,在本地同步 manifest 库
$ cd ~
$ git clone ~/review/git/platform/manifest.git
- 其次,增加新分支,并对 default.xml 作相应调整
$ cd ~/manifest
$ git checkout -b mybranch origin/master
$ head -12 defalut.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="myserver"
fetch=".." />
<default revision="mybranch "
remote="myserver"
sync-j="1" />
<project path="build" name="platform/build">
<copyfile src="core/root.mk" dest="Makefile" />
</project>
- 推送到代码库中
$ git add defalut.xml
$ git commit -m "modify manifest"
$ git push origin mybranch:mybranch