从零开始的Repo项目

Repo 是一个多项目协同管理工具,为组件化客户端项目提供便捷.
Repo 命令外挂与git命令之上,并非取代git.
当然Repo 项目里,您大多数时间依然使用git 命令来进行基本操作;但结合repo 指令,您可以做到使用更简洁的命令来执行多数git 重复操作.

1. 必要环境Python3(已安装则忽略)

安装python3
brew install python3
安装python2.7

点击进入官网下载安装包

2. 安装repo

根据自身情况二选一

/** 有梯子 */
mkdir -p ~/.bin
PATH="${HOME}/.bin:${PATH}"
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
chmod a+rx ~/.bin/repo
/** 无梯子(清华源) */
mkdir -p ~/.bin
PATH="${HOME}/.bin:${PATH}"
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/.bin/repo
chmod a+rx ~/.bin/repo
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'

找不到命令repo命令 zsh: command not found: repo 的解决办法

// 1. 打开.bash_profile文件,终端执行
vim .bash_profile
// 2. 在文件最下面添加一行,vim添加
PATH="${HOME}/.bin:${PATH}"
// 3. 终端执行
source ~/.bash_profile

3. 初始化项目

  • 第一步:manifest部分

(若已有同事创建好清单文件库,则忽略此步骤)

  1. 创建default.xml文件,内容如下:


    

    

    // 单独配置仓库中各项目参数,这里对单独一个做出注释
    

    

  1. 在gitlab(或github、gitee等等仓库工具)创建空项目,将default.xml丢到根目录下
  • 第二步:repo init部分

终端执行:

// 这里链接地址为default.xml所在的项目地址
repo init -u ssh://[email protected]/lyuxuming/manifest.git

注:无梯子同学请使用清华源,在repo init命令前,先执行如下操作:

mkdir -p ~/.bin
PATH="${HOME}/.bin:${PATH}"
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/.bin/repo
chmod a+rx ~/.bin/repo
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'

注:报错error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)的解决办法:

Downloading Repo source from https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
fatal: Cannot get https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/clone.bundle
fatal: error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)
fatal: double check your --repo-rev setting.
fatal: cloning the git-repo repository failed, will remove '.repo/repo'

// 注:您的Mac中Python3的文件夹可能不叫【Python 3.9】,注意修改一下这个路径哦~
sudo Applications/Python\ 3.9/Install\ Certificates.command
  • 第三步:repo sync部分

终端执行:

repo sync

若成功执行,各仓库项目此时已经按配置下载到本地各文件夹下,demo结构如下图:


demo结构图(pod组件化是另一件事了,这里不讨论)

注:若default.xml(manifest清单)中的配置没错,此时代码应该已经按照其指定分支全部拉取下来了,若报错,报错信息可读性很高,一般可以定位到哪里配置错误.


分割线:至此repo项目创建完成,当然也可以继续做进一步操作


4. 项目操作

  • repo status

执行以检查各组件(各git项目)状态

repo status
  • repo branch

执行以检查各组件(各git项目)所在分支

repo branch
  • repo forall -c

执行以一并操纵git仓库

// 所有仓库同时切换到某一分支
repo forall -c git checkout 
/** 这里不一一列举git命令了,fetch pull push add branch reset等等均与原有git命令相同,若想统一操作,则使用repo forall -c 接 git指令即可. */

你可能感兴趣的:(从零开始的Repo项目)