【Tools】Repo 工具完整使用手册

Repo 工具完整使用手册

(嵌入式 / Android / OpenHarmony 多仓库项目通用版)

一、Repo 是什么

Repo 是 Google 推出的多 Git 仓库管理工具,用于统一管理几十个甚至上百个 Git 子仓库。

  • 通过一个 manifest.xml 统一描述所有仓库地址、分支、路径
  • 用一套命令批量操作所有 Git 仓库
  • 常用于:Android、鸿蒙、芯片 BSP、Linux 大项目

二、基础安装(极简版)

Bash 复制代码
# 下载 repo
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

# 配置环境变量
export PATH=~/bin:$PATH

三、初始化仓库(最关键一步)

Bash 复制代码
repo init -u <manifest仓库地址> -b <分支> -m <manifest文件>

示例:

Bash 复制代码
repo init -u git@github.com:xxx/manifest.git -b master -m default.xml

作用:

  • 下载 manifest 仓库
  • 生成 .repo/ 目录
  • 记录所有子仓库信息

四、最常用核心命令(必须背熟)

1. 同步代码(日常更新)

Bash 复制代码
repo sync

2. 最推荐安全同步(企业标准)

Bash 复制代码
repo sync -c -d
  • -c:只拉当前分支,更快更小
  • -d:强制切回 manifest 指定的 commit,防止本地错乱

3. 多线程加速(常用 -j8)

Bash 复制代码
repo sync -c -d -j8

4. 同步后拉 Git LFS 大文件

Bash 复制代码
repo forall -c git lfs pull

五、批量操作命令(超级实用)

1. 在所有仓库执行任意命令

Bash 复制代码
repo forall -c "任意shell命令"

示例:

Bash 复制代码
repo forall -c git status
repo forall -c git branch
repo forall -c git clean -df

2. 显示每个仓库执行标题(方便看日志)

Bash 复制代码
repo forall -p -c git status

3. 只对某个仓库执行命令

Bash 复制代码
repo forall kernel-5.10 -c git checkout dev

六、查看信息类命令

1. 查看所有子仓库列表

Bash 复制代码
repo list

2. 查看每个仓库当前分支/状态

Bash 复制代码
repo info

3. 查看 manifest 路径

Bash 复制代码
repo manifest

七、分支操作(开发必备)

1. 给所有仓库新建并切换分支

Bash 复制代码
repo start 分支名 --all

2. 给指定仓库新建分支

Bash 复制代码
repo start dev kernel-5.10

3. 查看所有仓库当前分支

Bash 复制代码
repo branches

八、上传代码(repo upload)

适用于使用 Gerrit 做代码 review 的项目:

Bash 复制代码
repo upload

会批量把所有有改动的仓库推送到 Gerrit。

九、清理与重置

1. 丢弃所有本地修改(危险!)

Bash 复制代码
repo forall -c git reset --hard HEAD

2. 清理未跟踪文件

Bash 复制代码
repo forall -c git clean -df

3. 完全重置整个工程(错乱时救命)

Bash 复制代码
repo sync -c -d --force-sync

十、完整标准工作流(企业通用)

首次拉代码

Bash 复制代码
repo init -u git@xxx/manifest.git -b master
repo sync -c -d -j8
repo forall -c git lfs pull

日常更新

Bash 复制代码
repo sync -c -d
repo forall -c git lfs pull

开发修改

Bash 复制代码
repo start dev --all
# 修改代码
repo forall -c git status
repo forall -c git add .
repo forall -c git commit -m "update"

十一、常用参数速查表

参数 全称 作用
-c --current-branch 只拉当前分支,更快
-d --detach 强制对齐 manifest
-jN --jobs=N 多线程下载
-f --force 出错继续同步
--force-sync 强制覆盖同步
-p 执行命令时打印项目名

十二、常见问题 FAQ

1. repo sync 会覆盖我本地修改吗?

默认不会。

加 -d 也只会切 HEAD,不会删未提交修改。

真正危险的是 git reset --hard。

2. repo sync 和 git pull 区别?

  • git pull:单个仓库更新
  • repo sync:批量所有仓库 + 对齐 manifest

3. 为什么要 git lfs pull?

repo sync 不拉大文件,只拉指针,必须手动拉 LFS。

4. 仓库错乱怎么办?

Bash 复制代码
repo sync -c -d --force-sync
repo forall -c git reset --hard HEAD
相关推荐
棒子胡豆14 分钟前
Git总结
git
`流年づ2 天前
联邦学习-安全聚合
git·安全·github
喜欢吃燃面2 天前
Git 原理与使用(三):标签、多人协作与 Git Flow 落地
大数据·git·elasticsearch
喜欢吃燃面2 天前
Git 原理与使用(二):分支是平行宇宙,远程仓库是共享时空
大数据·git·elasticsearch
怪我冷i2 天前
Git主备分离,双仓库发布
git
解道Jdon2 天前
Rust重写OpenCode Rune:性能提升最高100倍
ide·windows·git·svn·eclipse·github·visual studio
黎羽_3 天前
终端/办公工具第二组:timewarrior + git-filter-repo + pre-commit + trafilatura + monolith
git·终端工具·开发效率·实战复盘
skywalk81633 天前
git上传的时候,它这个版的提交,是否包括了以前的改动? 比如下面这个,它前面的一些改动,会自动因为f91285c70dde 提交而提交吗?
git
Haooog4 天前
OpenHands 定时任务同步后还是关着?先查 Git Sync 的启停开关
git·agent·定时任务·配置管理·openhands
崖边看雾5 天前
Git 手册:三区、分支、撤销、冲突与团队协作
大数据·git·elasticsearch