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系统层的开发人员,其他开发人员很少使用,可能许多人没有了解过这个工具.其实可以不用翻墙也能使用这个工具,接下来的文档说明怎样在国内安装配置git repo工具.

安装

为了管理android由google开发的两个重要工具:

  1. 使用java语言开发的gerrit代码审核服务器;
  2. 使用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>
命令简短说明注释
helpDisplay detailed help on a command
initInitialize a repo client checkout in the current directory
syncUpdate working tree to the latest revision
startStart a new branch for development
checkoutCheckout a branch for development
forallRun a shell command in each project
uploadUpload changes for code review
prunePrune (delete) already merged topics
listList projects and their associated directories
statusShow the working tree status
branch, branchesView current topic branches
diffShow changes between commit and working tree
abandonPermanently abandon a development branch
cherry-pickCherry-pick a change.
diffmanifestsManifest diff utility
downloadDownload and checkout a change
grepPrint lines matching a pattern
infoGet info on the manifest branch, current branch or unmerged branches
manifestManifest inspection utility
overviewDisplay overview of unmerged project branches
rebaseRebase local branches on upstream branch
selfupdateUpdate repo to the latest version
smartsyncUpdate working tree to the latest known good revision
stageStage file(s) for commit
versionDisplay 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

gerrit: https://github.com/GerritCodeReview/gerrit.git

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值