【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
相关推荐
qq_4352879220 小时前
第9章 夸父逐日与后羿射日:死循环与进程终止?十个太阳同时值班的并行冲突
java·开发语言·git·死循环·进程终止·并行冲突·夸父逐日
AIMath~1 天前
Git 子模块(Submodule)目录结构清除实战复盘
git
切糕师学AI1 天前
Ubuntu 下 Git 完全使用指南
linux·git·ubuntu
一袋米扛几楼981 天前
【Git】规范化协作:详解 GitHub 工作流中的 Issue、Branch 与 Pull Request 最佳实践
前端·git·github·issue
尘埃落定wf1 天前
# GitHub CLI:告别繁琐的 Git 命令,让开发更高效
git·github
恋喵大鲤鱼1 天前
git clone
git·git clone
金牛IT1 天前
Gogs 轻量级 Git 服务器搭建与使用
运维·服务器·git
Qres8212 天前
Git安装记录
git
wj3055853782 天前
Codex + Git 开发环境配置指南(WSL版)
linux·运维·git
楠枬2 天前
Git 分支管理
git