repo 命令大全(第一篇 repo init)
前言
网上的repo学习教程都是比较分散的,没有一个统一的讲解,故结合chatgpt输出进行实操并记录下每个命令的用法
repo init
repo init
命令用于初始化一个工作区并配置清单(manifest)。这是使用 repo
的第一步,它会将 manifest
文件检出并准备好与代码库同步。这个命令包含很多选项,可以根据需要进行自定义。下面详细解释每个选项,并给出相应的例子。
基本选项
-
-h, --help
: 显示帮助信息并退出。repo init --help
用于查看所有支持的选项和详细说明。
日志选项
-
-v, --verbose
: 显示所有输出,通常用于调试或查看详细信息。repo init -v
详细输出整个初始化过程的每一步信息。
-
-q, --quiet
: 仅显示错误,抑制其他输出。repo init -q
安静模式下,只会显示错误信息,适合不需要查看详细过程的情况。
Manifest(清单)选项
-
-u URL, --manifest-url=URL
: 指定 manifest 仓库的 URL,repo 会从该仓库拉取 manifest 文件。repo init -u https://example.com/manifest.git
指定从
https://example.com/manifest.git
获取 manifest 仓库。 -
-b REVISION, --manifest-branch=REVISION
: 指定要使用的 manifest 分支或修订版本。默认是HEAD
。repo init -u https://example.com/manifest.git -b main
从 manifest 仓库的
main
分支初始化。 -
--manifest-upstream-branch=BRANCH
: 如果指定的--manifest-branch
是一个 commit,那么--manifest-upstream-branch
用于指定这个 commit 所在的上游分支。 -
-m NAME.xml, --manifest-name=NAME.xml
: 指定 manifest 文件的名字。默认情况下是default.xml
。repo init -u https://example.com/manifest.git -m custom.xml
从 manifest 仓库中拉取
custom.xml
文件,而不是默认的default.xml
。 -
-g GROUP, --groups=GROUP
: 只同步指定 group 中的项目,可以是多个 group 的组合。repo init -u https://example.com/manifest.git -g group1,group2
只同步属于
group1
和group2
的项目。 -
-p PLATFORM, --platform=PLATFORM
: 指定只同步与特定平台相关的项目,如linux
或darwin
。默认会自动检测平台。repo init -u https://example.com/manifest.git -p linux
只同步与 Linux 相关的项目。
-
--submodules
: 同步 manifest 仓库中的子模块(git submodules)。repo init -u https://example.com/manifest.git --submodules
同时拉取 manifest 仓库中定义的子模块。
-
--standalone-manifest
: 下载 manifest 文件作为静态文件,而不是创建 git 仓库检出。repo init -u https://example.com/manifest.git --standalone-manifest
直接下载 manifest 文件,而不检出 manifest 仓库。
-
--manifest-depth=DEPTH
: 使用指定的深度创建 manifest 仓库的浅克隆(0
表示全量克隆,默认为0
)。repo init -u https://example.com/manifest.git --manifest-depth=1
只克隆 manifest 仓库的最新一次提交。
Manifest 仓库检出选项
-
-c, --current-branch
: 只拉取当前 manifest 分支。repo init -u https://example.com/manifest.git -c
只拉取当前指定分支的内容。
-
--no-current-branch
: 拉取 manifest 仓库中的所有分支。repo init -u https://example.com/manifest.git --no-current-branch
拉取 manifest 仓库的所有分支。
-
--tags
: 拉取 manifest 仓库中的所有标签。repo init -u https://example.com/manifest.git --tags
同时拉取 manifest 仓库中的所有 git 标签。
-
--no-tags
: 不拉取 manifest 仓库中的标签。repo init -u https://example.com/manifest.git --no-tags
不拉取 manifest 仓库中的任何标签。
检出模式选项
-
--mirror
: 创建远程仓库的镜像,而不是检出工作区。这用于在本地镜像远程仓库。repo init -u https://example.com/manifest.git --mirror
创建远程仓库的完整镜像,而不检出工作目录。
-
--archive
: 以git archive
方式检出每个项目,而不是标准的 git 仓库。repo init -u https://example.com/manifest.git --archive
检出项目时生成归档文件,而不是完整的 git 仓库。
-
--worktree
: 使用git worktree
管理项目。repo init -u https://example.com/manifest.git --worktree
使用 git worktree 来管理工作区。
项目检出优化选项
-
--reference=DIR
: 指定镜像目录以加速克隆,常用于有本地镜像的情况。repo init -u https://example.com/manifest.git --reference=/path/to/mirror
使用指定的本地镜像
/path/to/mirror
加速项目克隆。 -
--dissociate
: 克隆完成后,从参考镜像中断开。repo init -u https://example.com/manifest.git --reference=/path/to/mirror --dissociate
克隆后不再与参考镜像关联。
-
--depth=DEPTH
: 使用指定的深度克隆项目,通常用于浅克隆。repo init -u https://example.com/manifest.git --depth=1
只克隆每个项目的最新一次提交。
-
--partial-clone
: 进行部分克隆,优化克隆大项目的时间和带宽。repo init -u https://example.com/manifest.git --partial-clone
启用部分克隆。
-
--partial-clone-exclude=PARTIAL_CLONE_EXCLUDE
: 在部分克隆中排除指定项目。repo init -u https://example.com/manifest.git --partial-clone --partial-clone-exclude=large_project
在部分克隆时排除
large_project
项目。 -
--clone-filter=CLONE_FILTER
: 为部分克隆指定过滤器,默认是blob:none
。repo init -u https://example.com/manifest.git --clone-filter=tree:0
使用
tree:0
过滤器进行部分克隆。 -
--use-superproject
: 使用 manifest 仓库中的 superproject 来同步项目。repo init -u https://example.com/manifest.git --use-superproject
使用 superproject 功能来同步项目。
-
--clone-bundle
: 启用clone.bundle
加速 HTTP/HTTPS 的克隆(默认启用,除非部分克隆)。repo init -u https://example.com/manifest.git --clone-bundle
使用
/clone.bundle
文件加速克隆。 -
--no-clone-bundle
: 禁用clone.bundle
。repo init -u https://example.com/manifest.git --no-clone-bundle
禁用
/clone.bundle
文件。 -
--git-lfs
: 启用 Git LFS 支持。repo init -u https://example.com/manifest.git --git-lfs
启用 Git LFS 来处理大文件。
-
--no-git-lfs
: 禁用 Git LFS 支持。repo init -u https://example.com/manifest.git --no-git-lfs
禁用 Git LFS。
repo 版本选项
-
--repo-url=URL
: 指定 repo 仓库的 URL。repo init --repo-url=https://example.com/repo.git
从指定的
repo
仓库 URL 中拉取repo
工具。 -
--repo-rev=REV
: 指定 repo 分支或修订版本。repo init --repo-url=https://example.com/repo.git --repo-rev=v2.20
使用指定版本的
repo
工具。 -
--no-repo-verify
: 不验证repo
的源代码。repo init --repo-url=https://example.com/repo.git --no-repo-verify
禁用对
repo
仓库的验证。
其他选项
-
--config-name
: 总是提示输入用户名和电子邮件。repo init -u https://example.com/manifest.git --config-name
初始化时总是提示设置用户的名字和电子邮件。
多清单选项
-
--outer-manifest
: 操作从最外层的 manifest 开始。repo init -u https://example.com/manifest.git --outer-manifest
从最外层的清单开始操作。
-
--this-manifest-only
: 仅操作当前 manifest 文件。repo init -u https://example.com/manifest.git --this-manifest-only
只操作当前的 manifest 文件,不涉及子清单。