git-repo系列教程(1) 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系统层的开发人员,其他开发人员很少使用,可能许多人没有了解过这个工具.其实可以不用FQ也能使用这个工具,接下来的文档说明怎样在国内安装配置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 <command>
命令 | 简短说明 | 注释 |
---|---|---|
help | Display detailed help on a command | |
init | Initialize a repo client checkout in the current directory | |
sync | Update working tree to the latest revision | |
start | Start a new branch for development | |
checkout | Checkout a branch for development | |
forall | Run a shell command in each project | |
upload | Upload changes for code review | |
prune | Prune (delete) already merged topics | |
list | List projects and their associated directories | |
status | Show the working tree status | |
branch, branches | View current topic branches | |
diff | Show changes between commit and working tree | |
abandon | Permanently abandon a development branch | |
cherry-pick | Cherry-pick a change. | |
diffmanifests | Manifest diff utility | |
download | Download and checkout a change | |
grep | Print lines matching a pattern | |
info | Get info on the manifest branch, current branch or unmerged branches | |
manifest | Manifest inspection utility | |
overview | Display overview of unmerged project branches | |
rebase | Rebase local branches on upstream branch | |
selfupdate | Update repo to the latest version | |
smartsync | Update working tree to the latest known good revision | |
stage | Stage file(s) for commit | |
version | Display 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://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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话