Repo 是一個多項(xiàng)目協(xié)同管理工具,為組件化客戶端項(xiàng)目提供便捷.
Repo 命令外掛與git命令之上,并非取代git.
當(dāng)然Repo 項(xiàng)目里,您大多數(shù)時間依然使用git 命令來進(jìn)行基本操作;但結(jié)合repo 指令,您可以做到使用更簡潔的命令來執(zhí)行多數(shù)git 重復(fù)操作.
1. 必要環(huán)境Python3(已安裝則忽略)
安裝python3
brew install python3
安裝python2.7
2. 安裝repo
根據(jù)自身情況二選一
/** 有梯子 */
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文件,終端執(zhí)行
vim .bash_profile
// 2. 在文件最下面添加一行,vim添加
PATH="${HOME}/.bin:${PATH}"
// 3. 終端執(zhí)行
source ~/.bash_profile
3. 初始化項(xiàng)目
-
第一步:manifest部分
(若已有同事創(chuàng)建好清單文件庫,則忽略此步驟)
- 創(chuàng)建default.xml文件,內(nèi)容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<manifest>
<remote
name="origin" // 倉庫名,依照自己git倉庫填寫,這里只做示例,下同
fetch="ssh://git@gitlab.com/lyuxuming" // 倉庫地址,建議使用ssh鏈接(也可使用https)
revision="master" // 默認(rèn)分支(默認(rèn)從該分支上獲取代碼)
/>
<default
revision="master" // revision的默認(rèn)值,下面project中沒有配置revision時,使用此值
remote="origin" // remote的默認(rèn)值,下面project中沒有配置remote時,使用此值
sync-j="4"
/>
// 單獨(dú)配置倉庫中各項(xiàng)目參數(shù),這里對單獨(dú)一個做出注釋
<project
path="XHMain" // 拉取代碼后的相對路徑
name="XHMain" // 項(xiàng)目名,與remote.fetch做拼接即是完整項(xiàng)目地址,示例ssh://git@gitlab.com/lyuxuming/XHMain
remote="origin" // 倉庫名
revision="master" // 默認(rèn)拉取的分支名
/>
<project
path="XHBusiness/XHAuthbusiness"
name="XHAuthbusiness"
remote="origin"
revision="master"
/>
</manifest>
- 在gitlab(或github、gitee等等倉庫工具)創(chuàng)建空項(xiàng)目,將default.xml丟到根目錄下
-
第二步:repo init部分
終端執(zhí)行:
// 這里鏈接地址為default.xml所在的項(xiàng)目地址
repo init -u ssh://git@gitlab.com/lyuxuming/manifest.git
注:無梯子同學(xué)請使用清華源,在repo init命令前,先執(zhí)行如下操作:
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'
注:報(bào)錯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部分
終端執(zhí)行:
repo sync
若成功執(zhí)行,各倉庫項(xiàng)目此時已經(jīng)按配置下載到本地各文件夾下,demo結(jié)構(gòu)如下圖:

注:若default.xml(manifest清單)中的配置沒錯,此時代碼應(yīng)該已經(jīng)按照其指定分支全部拉取下來了,若報(bào)錯,報(bào)錯信息可讀性很高,一般可以定位到哪里配置錯誤.
分割線:至此repo項(xiàng)目創(chuàng)建完成,當(dāng)然也可以繼續(xù)做進(jìn)一步操作
4. 項(xiàng)目操作
-
repo status
執(zhí)行以檢查各組件(各git項(xiàng)目)狀態(tài)
repo status
-
repo branch
執(zhí)行以檢查各組件(各git項(xiàng)目)所在分支
repo branch
-
repo forall -c <git指令>
執(zhí)行以一并操縱git倉庫
// 所有倉庫同時切換到某一分支
repo forall -c git checkout <branchName>
/** 這里不一一列舉git命令了,fetch pull push add branch reset等等均與原有g(shù)it命令相同,若想統(tǒng)一操作,則使用repo forall -c 接 git指令即可. */