概述
Repo 是我们以 Git 为基础构建的代码库管理工具。Repo 可以在必要时整合多个 Git 代码库,将相关内容上传到我们的修订版本控制系统,并自动执行 Android 开发工作流程的部分环节。
Repo 并非用来取代 Git,只是为了让您在 Android 环境中更轻松地使用 Git。
应用场景:
- 大型软件开发项目:多仓,多分支,多流程
- 多仓管理:多责任田,多评审网站等
- 搭配Gerrit使用
Repo环境搭建
创建repo仓
该仓主要是管理repo工具和脚本, 该仓在repo init过程中会下载。
git clone https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
安装repo到系统环境
cp git-repo/repo ~/bin/
将git-repo仓入库到个人办公环境的代码中心库。我这里放在码云上面,并且在里面做了一些定制。
git clone https://gitee.com/whilewell/git-repo.git
创建manifest仓
manifest仓主要存放是xml文件,该文件中存放是对各个git仓的管理信息,以我个人的openwrt工程openwrt.xml为例, 下面是openwrt.xml内容。
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote fetch="https://gitee.com/whilewell/" name="origin" />
<default remote="origin" revision="master" sync-j="4" />
<!--===========top===============-->
<project name="openwrt-topdir" path="topdir" >
<linkfile src="BSDmakefile" dest="BSDmakefile" />
<linkfile src="Config.in" dest="Config.in" />
<linkfile src="feeds.conf.default" dest="feeds.conf.default" />
<linkfile src="Makefile" dest="Makefile" />
<linkfile src="rules.mk" dest="rules.mk" />
<linkfile src="COPYING" dest="COPYING" />
</project>
<!--===========config==============-->
<project name="openwrt-config" path="config" />
<!--===========dl==============-->
<project name="openwrt-dl" path="dl" />
<project name="linux-kernel" path="dl/linux" >
<runshell mode="shell" shell="adapt.sh" cmd="xxx" />
<linkfile src="linux-5.4.155.tar.xz" dest="dl/linux-5.4.155.tar.xz" />
</project>
<!--===========feeds==============-->
<project name="openwrt-feeds-luci" path="feeds/luci" />
<project name="openwrt-feeds-packages" path="feeds/packages" />
<project name="openwrt-feeds-routing" path="feeds/routing" />
<project name="openwrt-feeds-targets" path="feeds/targets" />
<!--===========includes==============-->
<project name="openwrt-include" path="include" />
<!--===========LICENSES==============-->
<project name="openwrt-license" path="LICENSES" />
<!--===========package==============-->
<project name="openwrt-package" path="package" />
<!--===========scripts==============-->
<project name="openwrt-scripts" path="scripts" />
<!--===========target==============-->
<project name="openwrt-target" path="target" />
<!--===========toolchain==============-->
<project name="openwrt-toolchain" path="toolchain" />
<!--===========tools==============-->
<project name="openwrt-tools" path="tools" />
</manifest>
个人的manifest仓的状态
Repo环境使用
repo 工具使用格式
repo init -u manifest仓链接 -b manifest仓分支 -m manifest仓中xml名称 --no-repo-verify --repo-url= repo仓链接 --repo-branch=repo仓分支
以我下载个人openwrt项目为例:
repo init -u https://gitee.com/whilewell/manifest.git -b master -m openwrt.xml --no-repo-verify --repo-url=https://gitee.com/whilewell/git-repo.git --repo-branch=master
执行后会在当前目录创建一个.repo目录,该目录下面会有repo仓和manifest仓
wsk@wsk:~/test-repo/.repo$ tree -L 1
.
├── manifests
├── manifests.git
├── manifest.xml
└── repo
然后我们单独下载一个仓: repo sync -c openwrt-config
wsk@wsk:~/test-repo$ repo sync -c openwrt-config
Fetching: 100% (1/1), done in 1.156s
Garbage collecting: 100% (1/1), done in 0.006s
repo sync has finished successfully.
wsk@wsk:~/test-repo$
wsk@wsk:~/test-repo$ ll
total 16
drwxrwxr-x 4 wsk wsk 4096 Nov 25 15:10 ./
drwxr-xr-x 14 wsk wsk 4096 Nov 25 15:10 ../
drwxrwxr-x 3 wsk wsk 4096 Nov 25 15:10 config/
drwxrwxr-x 7 wsk wsk 4096 Nov 25 15:10 .repo/
wsk@wsk:~/test-repo$
常用的repo命令
- 代码下载:repo sync ; repo sync -c xxx
- 创建分支:repo start xx --all
- 全仓执行命令:repo forall -c "git status ; git diff"
- 代码提交:repo upload . ; repo upload
- 查看帮助:repo --help
参考
- repo中manifest解析 - 代码先锋网
- git-repo 文档 – git-repo | git-repo 与repo类同,可以参考使用