Repo是一个基于git的仓库管理工具,它由python语言实现,使用Repo,可以将很多的git仓库一起打包管理,做统一的git操作,完成仓库管理任务。Repo 并不是用来取代 Git的,它是使用 Python 对 Git 的一层封装,简化了对多个 Git 版本库的管理方式。Repo 主要是结合着 Gerrit 来使用,它以一个manifest.xml
为中心,通过对项目结构化的描述,达到与 Submodule 同样的效果,但是比 Submodule 更加灵活和方便。
安装repo环境:
repo环境包括两部分,第一部分是repo命令本身,它是一个python可执行脚本文件,另一部分是一个名字叫做repo.git仓库。示意如下:
下面我们就逐步安装这两部分:
在root模式下,输入以下命令,安装repo工具:
curl https://storage.googleapis.com/git-repo-downloads/repo > /bin/repo
退出root用户,执行命令添加repo的可执行权限。
此时可以运行它以下,你会得到要给错误报告,这是因为我们还没完成第二步.
通过repo help也可以看出这一点:
下一步,就是按照提示要求,执行"repo init"完成repo运行环境安装的第二步.
repo init
最后的错误和仓库清单描述文件相关,和git-repo.git仓库无关,暂时不用理会。git-repo.git仓库已经成功下载下来了,见下图的隐藏目录:
关于git-repo.git仓库的下载原理,为什么会去一个指定地址检出代码呢?答案肯定在repo脚本里,在repo里面会用到两个变量,打开/bin/repo文件,查看REPO_URL/REPO_REV的定义:
可以看到,REPO_URL/REPO_REV分别是repo.git仓库的url和检出的branch. 如果我们要想让repo来clone我们自己的repo.git,则修改上边的变量就可以了,在环境变量没有定义REPO_URL的情况下,repo工具将自动从谷歌的git-repo仓库下载。如果用户有自定义的实现,可以首先设置REPO_URL/REPO_REV环境变量。
再次执行repo help,可以看到命令多除了好多:
czl@czl-VirtualBox:~/repo-study$ repo help
usage: repo COMMAND [ARGS]
The most commonly used repo commands are:
abandon Permanently abandon a development branch
branch View current topic branches
branches View current topic branches
checkout Checkout a branch for development
cherry-pick Cherry-pick a change.
diff Show changes between commit and working tree
diffmanifests Manifest diff utility
download Download and checkout a change
gitc-delete Delete a GITC Client.
gitc-init Initialize a GITC Client.
grep Print lines matching a pattern
info Get info on the manifest branch, current branch or unmerged branches
init Initialize a repo client checkout in the current directory
list List projects and their associated directories
overview Display overview of unmerged project branches
prune Prune (delete) already merged topics
rebase Rebase local branches on upstream branch
smartsync Update working tree to the latest known good revision
stage Stage file(s) for commit
start Start a new branch for development
status Show the working tree status
sync Update working tree to the latest revision
upload Upload changes for code review
See 'repo help <command>' for more information on a specific command.
See 'repo help --all' for a complete list of recognized comma