Repo工具使用


概述

Repo 是我們以 Git 為基礎構建的代碼庫管理工具。Repo 可以在必要時整合多個 Git 代碼庫,將相關內容上傳到我們的修訂版本控制系統,並自動執行 Android 開發工作流程的部分環節。
Repo 並非用來取代 Git,只是為了讓您在 Android 環境中更輕松地使用 Git。

應用場景:

  • 大型軟件開發項目:多倉,多分支,多流程
  • 多倉管理:多責任田,多評審網站等
  • 搭配Gerrit使用

Repo環境搭建

創建repo倉

該倉主要是管理repo工具和腳本, 該倉在repo init過程中會下載。

git clone https://mirrors.tuna.tsinghua.edu.cn/git/git-repo

安裝repo到系統環境
cp git-repo/repo ~/bin/

將git-repo倉入庫到個人辦公環境的代碼中心庫。我這里放在碼雲上面,並且在里面做了一些定制。

git clone https://gitee.com/whilewell/git-repo.git

創建manifest倉

manifest倉主要存放是xml文件,該文件中存放是對各個git倉的管理信息,以我個人的openwrt工程openwrt.xml為例, 下面是openwrt.xml內容。

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <remote fetch="https://gitee.com/whilewell/" name="origin" />
  <default remote="origin" revision="master" sync-j="4" />

  <!--===========top===============-->
  <project name="openwrt-topdir" path="topdir" >
	  <linkfile src="BSDmakefile" dest="BSDmakefile" />
	  <linkfile src="Config.in" dest="Config.in" />
	  <linkfile src="feeds.conf.default" dest="feeds.conf.default" />
	  <linkfile src="Makefile" dest="Makefile" />
	  <linkfile src="rules.mk" dest="rules.mk" />
	  <linkfile src="COPYING" dest="COPYING" />
  </project>

  <!--===========config==============-->
  <project name="openwrt-config" path="config" />

  <!--===========dl==============-->
  <project name="openwrt-dl" path="dl" />
  <project name="linux-kernel" path="dl/linux" >
	  <runshell mode="shell" shell="adapt.sh" cmd="xxx" />
	  <linkfile src="linux-5.4.155.tar.xz" dest="dl/linux-5.4.155.tar.xz" />
  </project>

  <!--===========feeds==============-->
  <project name="openwrt-feeds-luci" path="feeds/luci" />
  <project name="openwrt-feeds-packages" path="feeds/packages" />
  <project name="openwrt-feeds-routing" path="feeds/routing" />
  <project name="openwrt-feeds-targets" path="feeds/targets" />

  <!--===========includes==============-->
  <project name="openwrt-include" path="include" />

  <!--===========LICENSES==============-->
  <project name="openwrt-license" path="LICENSES" />

  <!--===========package==============-->
  <project name="openwrt-package" path="package" />

  <!--===========scripts==============-->
  <project name="openwrt-scripts" path="scripts" />

  <!--===========target==============-->
  <project name="openwrt-target" path="target" />

  <!--===========toolchain==============-->
  <project name="openwrt-toolchain" path="toolchain" />

  <!--===========tools==============-->
  <project name="openwrt-tools" path="tools" />
</manifest>

個人的manifest倉的狀態

Repo環境使用

repo 工具使用格式

repo init -u manifest倉鏈接 -b manifest倉分支 -m manifest倉中xml名稱 --no-repo-verify --repo-url= repo倉鏈接 --repo-branch=repo倉分支

以我下載個人openwrt項目為例:

repo init -u https://gitee.com/whilewell/manifest.git -b master -m openwrt.xml --no-repo-verify --repo-url=https://gitee.com/whilewell/git-repo.git --repo-branch=master

執行后會在當前目錄創建一個.repo目錄,該目錄下面會有repo倉和manifest倉

wsk@wsk:~/test-repo/.repo$ tree -L 1
.
├── manifests
├── manifests.git
├── manifest.xml
└── repo

然后我們單獨下載一個倉: repo sync -c openwrt-config

wsk@wsk:~/test-repo$ repo sync -c openwrt-config
Fetching: 100% (1/1), done in 1.156s
Garbage collecting: 100% (1/1), done in 0.006s
repo sync has finished successfully.
wsk@wsk:~/test-repo$
wsk@wsk:~/test-repo$ ll
total 16
drwxrwxr-x  4 wsk wsk 4096 Nov 25 15:10 ./
drwxr-xr-x 14 wsk wsk 4096 Nov 25 15:10 ../
drwxrwxr-x  3 wsk wsk 4096 Nov 25 15:10 config/
drwxrwxr-x  7 wsk wsk 4096 Nov 25 15:10 .repo/
wsk@wsk:~/test-repo$

常用的repo命令

  • 代碼下載:repo sync ; repo sync -c xxx
  • 創建分支:repo start xx --all
  • 全倉執行命令:repo forall -c "git status ; git diff"
  • 代碼提交:repo upload . ; repo upload
  • 查看幫助:repo --help

參考


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM