文章目录
git repo 简介安装帮助准备清单库拉取git-repo仓库和清单库命令格式文件夹描述同步仓库学习资料文章官网
git repo 简介
使用svn和git多年,深刻体会到svn和git各有优缺点,其他的不多说,网上资料很多,说说git最大的缺点: git相对于svn来说,不能部分检出,只能全部检出,这就导致即使git优点很多,svn也会有一席之地.
为了解决git的缺点,就需要把git分成许多小的独立的仓库.怎么管理大量的独立的git仓库呢? git实现了submodule子模块功能,但是git子模块限制很多,使用子模块管理大量git多仓库很不现实,只适合很少的多仓库管理.
google开发了android系统,android系统由许多git仓库组成,google为了管理这些许多仓库,开发了两个工具:repo和gerrit. gerrit为代码审核服务器,repo是多仓库管理客户端. 其实repo可以单独使用,管理非android的其他项目.
repo客户端是使用python开发的命令行工具,是对git命令行工具的补充,用来管理多仓库,在使用repo之前,一定要非常熟悉git命令才可以.
由于google被中国屏蔽了,导致国内除非做android系统层的开发人员,其他开发人员很少使用,可能许多人没有了解过这个工具.其实可以不用翻墙也能使用这个工具,接下来的文档说明怎样在国内安装配置git repo工具.
安装
为了管理android由google开发的两个重要工具:
使用java语言开发的gerrit代码审核服务器;使用python开发的repo命令行工具.
#shell
#python
.repo/repo/main.py
使用清华开源镜像:https://mirrors.tuna.tsinghua.edu.cn/help/git-repo/
mkdir ~/bin
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod a+x ~/bin/repo
vim ~/.bashrc
export PATH="$PATH:~/bin"
#repo的运行过程中会尝试访问官方的git源更新自己,如果想使用tuna的镜像源进行更新,可以将如下内容复制到你的~/.bashrc里
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
source ~/.bashrc
repo version
#repo引导文件理解
执行repo init时会下载repo的主体部分,并放在当前目录的.repo/repo目录下。repo主体部分默认从https://gerrit.googlesource.com/git-repo获取。
可以使用其他镜像源来获取,如清华源。下面列举两种方式解决repo源问题:
方法一:
每次执行repo init时,增加选项:--repo-url=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo 指定repo源。
方法二:(推荐)
设置环境变量REPO_URL
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
可以将环境变量写在/etc/profile或~/.bashrc中.
帮助
# 蒋鑫Git权威指南带书签完整版.pdf -> 第25章android 式多版本库协同
repo --help
# command 对应 .repo/repo/subcmds 目录下的python文件
repo help
命令简短说明注释helpDisplay detailed help on a commandinitInitialize a repo client checkout in the current directorysyncUpdate working tree to the latest revisionstartStart a new branch for developmentcheckoutCheckout a branch for developmentforallRun a shell command in each projectuploadUpload changes for code reviewprunePrune (delete) already merged topicslistList projects and their associated directoriesstatusShow the working tree statusbranch, branchesView current topic branchesdiffShow changes between commit and working treeabandonPermanently abandon a development branchcherry-pickCherry-pick a change.diffmanifestsManifest diff utilitydownloadDownload and checkout a changegrepPrint lines matching a patterninfoGet info on the manifest branch, current branch or unmerged branchesmanifestManifest inspection utilityoverviewDisplay overview of unmerged project branchesrebaseRebase local branches on upstream branchselfupdateUpdate repo to the latest versionsmartsyncUpdate working tree to the latest known good revisionstageStage file(s) for commitversionDisplay the version of repo
准备清单库
repo里程碑签名进行严格的验证
代码审核服务器
manifest-server XMLRPC
repo sync --smart-sync
manifest-format.md
拉取git-repo仓库和清单库
命令格式
repo init -u manifest_git_path -m manifest_file_name -b branch_name --repo-url=repo_url --no-repo-verify
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
# manifest repository location
https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
#initial manifest file
default.xml
#manifest branch or revision
HEAD
repo init -u http://10.147.20.116:3000/manifest/language.git -m cxx_prj.xml -b master --no-repo-verify --repo-url=http://10.147.20.116:3000/git/git-repo.git
执行repo init命令后,会在当前目录创建一个.repo隐藏文件夹。
tree aosp/ -La 2
aosp/
└── .repo
├── manifests
├── manifests.git
├── manifest.xml
├── repo
└── TRACE_FILE
文件夹描述
manifests : manifest仓库(清单库)内容,即repo init的-u选项对应的仓库manifests.git : manifest仓库(清单库)的.git目录manifest.xml 指明当前生效的Manifest文件,即repo init的-m选项对应的参数(没有该选项时默认为default.xml)
同步仓库
repo sync
sudo apt install xsltproc
学习资料
文章
Git repo工具使用教程: https://blog.csdn.net/zhulianseu/article/details/129727500
git&repo入门: https://blog.csdn.net/ASCIIZUO/article/details/125841987
Repo 安装初始化(试过OK): https://blog.csdn.net/linpuliang/article/details/123510711
Repo 使用详解: https://www.jianshu.com/p/9c57696165f3
Google Git-Repo 多仓库项目管理 : https://zhuanlan.zhihu.com/p/50564255
Git多项目管理 : https://www.jianshu.com/p/284ded3d191b
使用 repo 管理项目代码 —— repo 清单配置: https://blog.csdn.net/zhe_d/article/details/83934231
官网
git-repo: https://github.com/GerritCodeReview/git-repo.git
repo - The Multiple Git Repository Tool: https://gerrit.googlesource.com/git-repo
AOSP源代码控制工具: https://source.android.com/docs/setup/download?hl=zh-cn
gerrit: https://github.com/GerritCodeReview/gerrit.git