前文講述 repo 命令詳解,從實(shí)踐中來理論 又到實(shí)踐中去。仔細(xì)研究會發(fā)現(xiàn),可將重復(fù)工作交給 repo 實(shí)現(xiàn),接下來簡單講講兩種場景簡單應(yīng)用。
a) repo 鏡像倉變更
b) repo 更新代碼倉
Gerrit 管理源碼托管服務(wù)器難免發(fā)生故障,必要時需要數(shù)據(jù)遷移到另外一臺服務(wù)器。此時 gitolite 可能需要重構(gòu),代碼倉路徑則會發(fā)生變更;重新同步代碼時間過長,能否在原基礎(chǔ)上切換代碼倉? 當(dāng)然可以。
1.1 鏡像倉變更原理每個代碼倉通過切換 remote url 方式,可實(shí)現(xiàn)同步遠(yuǎn)程倉變更;從單個倉延拓到全部倉即可彎沉代碼倉變更。
git remote set-url origin_name url_name
借助 Gerrit 執(zhí)行腳本方式,協(xié)助完成
repo forall -c xxx.sh
1.2 鏡像倉變更示例如果僅僅是代碼托管服務(wù)區(qū)變更或者 gitolite 路徑變更,簡單編寫篩選倉庫源名并替換相關(guān) URL 腳本 url_change.sh。
例如原來代碼倉路徑 git@192.168.17.24:356x-r/xxxx 變更為 git@192.168.14.38:rk356x-r
簡單編寫腳本 即可實(shí)現(xiàn)代碼遷移。
#!/bin/bash
# *********************** #
# Author by Sanle
# *********************** #
URLA='git@192.168.17.24:356x-r'
URLB='git@192.168.14.38:rk356x-r'
if echo "$(git remote get-url $(git remote))" | grep -qwi $URLA ; then
remote_path=$(git remote get-url $(git remote) | awk -F $URLA '{print $2 }')
git remote set-url $(git remote) $URLB$remote_path
echo remote set-url $(git remote) $URLB$remote_path
fi
exit 0
啟動 repo 執(zhí)行腳本,等待執(zhí)行完成即可完成代碼倉遷移。
cd 356x-android11
.repo/repo/repo forall -c ~/356x-android11/url-change.sh
2 repo 拉取制定分支更新代碼同步時偶爾會出現(xiàn)代碼倉遺漏或者代碼倉更新不及時,編譯時輕則功能缺失;重則編譯失敗,查找原因費(fèi)時費(fèi)力不說,還影響敲鍵盤的心情。如何快速精準(zhǔn)實(shí)現(xiàn)代碼更新呢? 推薦使用 repo 同步
2.1 編寫代碼同步腳本以 rk3568 android 為例,同步代碼分支名為 demo。
touch repo_sync.sh
chmod +x repo_sync.sh
vi repo_sync.sh
#!/bin/bash
if [ -z "$1" ]; then
rd_branch=("demo")
else
rd_branch=($1)
fi
rd_remote=("aosp" "rk" "rk29")
remote=$(git remote)
echo `pwd`
git fetch $remote
for _remote in ${rd_remote[@]}
do
if [ "$_remote" == "$remote" ]; then
for branch in ${rd_branch[@]}
do
if [ ! -z "$(git branch -r --list $remote/$branch)" ]; then
echo "$remote-->$branch"
if [ -z "$(git branch $branch --contains)" ]; then
git checkout -t $remote/$branch
else
if ! echo "$(git branch | grep '\*')" | grep -qwi "$branch" ; then
git checkout $branch
if [ $? -ne 0 ]; then
exit $?
fi
fi
git pull $remote $branch
fi
fi
done
fi
done
exit 0
2.2 同步所有代碼倉單倉執(zhí)行 repo_sync.sh 可實(shí)現(xiàn)代碼倉同步制定分支,借助 repo forall 命令將所有代碼倉執(zhí)行一次腳本即可實(shí)現(xiàn)代碼倉同步。
# 等待完成后,所有倉庫同步完成,并切換到 demo 分支
.repo/repo/repo forall -c ~/rk3568-s/repo_sync.sh demo
總結(jié)從實(shí)踐中來,到實(shí)踐中去。
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧
標(biāo)題名稱:repo進(jìn)階-創(chuàng)新互聯(lián)
網(wǎng)頁鏈接:http://aaarwkj.com/article48/cdpchp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、搜索引擎優(yōu)化、網(wǎng)站建設(shè)、做網(wǎng)站、手機(jī)網(wǎng)站建設(shè)、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容