从零开始的repo项目(极速版)

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

安装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'

报错解决办法请查看:详细版

3. 初始化项目

  • 第一步:manifest部分

  1. 创建default.xml文件,内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<manifest>
    <remote
        name="origin" // 仓库名,依照自己git仓库填写,这里只做示例,下同
        fetch="ssh://git@gitlab.com/lyuxuming" // 仓库地址,建议使用ssh链接(也可使用https)
        revision="master" // 默认分支(默认从该分支上获取代码)
    />

    <default
        revision="master" // revision的默认值,下面project中没有配置revision时,使用此值
        remote="origin" // remote的默认值,下面project中没有配置remote时,使用此值
        sync-j="4"
    />

    // 单独配置仓库中各项目参数,这里对单独一个做出注释
    <project
        path="XHMain" // 拉取代码后的相对路径
        name="XHMain" // 项目名,与remote.fetch做拼接即是完整项目地址,示例ssh://git@gitlab.com/lyuxuming/XHMain
        remote="origin" // 仓库名
        revision="master" // 默认拉取的分支名
    />

    <project
        path="XHBusiness/XHAuthbusiness"
        name="XHAuthbusiness"
        remote="origin"
        revision="master"
    />
</manifest>
  1. 在gitlab(或github、gitee等等仓库工具)创建空项目,将default.xml丢到根目录下
  • 第二步:repo init部分

终端执行:

// 这里链接地址为default.xml所在的项目地址
repo init -u ssh://git@gitlab.com/lyuxuming/manifest.git

报错解决办法请查看:详细版

  • 第三步: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指令>

执行以一并操纵git仓库

// 所有仓库同时切换到某一分支
repo forall -c git checkout <branchName>
/** 这里不一一列举git命令了,fetch pull push add branch reset等等均与原有git命令相同,若想统一操作,则使用repo forall -c 接 git指令即可. */
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容