Repo¶
- 目录结构
manifests manifests.git manifest.xml project.list project-objects projects repo .repo_fetchtimes.json 1)manifests: 这个目录通常包含了多个清单文件(manifest files),这些文件定义了如何获取和管理多个 Git 仓库的集合。 2)manifests.git: 这是一个 Git 仓库,存储了清单文件的版本历史。它允许你跟踪和管理清单文件的变化。 3)manifest.xml: 这是一个主要的清单文件,定义了项目的结构和各个子项目的来源(即它们的 Git 仓库地址和分支)。 4)project.list: 这个文件列出了所有项目的清单,通常用于快速查看当前管理的项目。 5)project-objects: 这个目录通常用于存储项目的对象数据,可能与 Git 对象相关。 6)projects: 这个目录包含了所有被管理的项目的子目录,每个子目录对应一个 Git 仓库。 7)repo: 这是一个可执行文件,通常用于管理和操作 .repo 目录中的项目和清单。 8).repo_fetchtimes.json: 这个文件记录了上次获取(fetch)操作的时间,可能用于优化后续的获取操作。
- 显示当前清单文件
.repo/repo/repo manifest -r 1)显示清单文件:输出当前 repo 项目的清单文件内容,通常是 XML 格式,包含所有子项目的信息。 2)递归显示:-r 选项表示递归地显示所有子项目的清单信息,包括它们的路径、分支、提交等。
- 显示当前 Git 仓库的状态信息
.repo/repo/repo status: 1)未跟踪的文件:列出当前目录中未被 Git 跟踪的文件。 2)已修改的文件:显示已修改但尚未提交的文件。 3)已暂存的文件:列出已添加到暂存区但尚未提交的文件。 4)分支信息:显示当前所在的分支以及与远程分支的差异(如是否有未推送的提交)。
- 同步本地的最新提交
.repo/repo/repo sync -l 注:在执行 repo sync -l 命令时,默认情况下会调用 .repo/manifests/default.xml 文件作为清单文件。这个文件定义了要同步的项目及其对应的 Git 仓库和分支。 如果要手动选择.repo/manifests下的清单文件,可使用 repo sync -l -m manifest.xml
- 同步远程的最新提交
.repo/repo/repo sync -c --no-tags 注:如果使用.repo/repo/repo sync -c --no-tags时报错如下: Fetching projects: 100% (55/55), done. info: A new version of repo is available warning: project 'repo' branch 'default' is not signed warning: Skipped upgrade to unverified version error: Cannot remove project "docs/.Socs": uncommitted changes are present commit changes, then run sync again 类似的这这种错误必须解决,不然中断以后,可能导致其它文件的Fetching不全,解决方法如下: cd docs/.Socs/ git checkout . git status Not currently on any branch. Untracked files: (use "git add <file>..." to include in what will be committed) RK3588/Rockchip_Developer_Guide_Linux_Software_CN.pdf mv RK3588/Rockchip_Developer_Guide_Linux_Software_CN.pdf ../../(备份文件,或者直接删除文件) git status Not currently on any branch. nothing to commit, working directory clean .repo/repo/repo sync -c --no-tags
- 在所有项目下新建分支
.repo/repo/repo start firefly --all
- 命令解释
.repo/repo/repo sync -l: 作用: 这个命令会同步当前工作目录中的所有项目,但只会更新到本地的最新提交(即只更新到本地的 HEAD),而不会进行任何网络操作。 选项: -l(或 --local-only)选项表示只使用本地的 Git 仓库,不会从远程仓库拉取更新。这对于在本地开发时,确保不影响远程仓库的状态非常有用。 .repo/repo/repo sync -c --no-tags: 作用: 这个命令会同步所有项目,并且会从远程仓库拉取最新的提交。 选项: -c(或 --current-branch)选项表示只同步当前分支的更新,而不是所有分支。 --no-tags 选项表示在同步时不拉取任何标签(tags)。这可以加快同步速度,尤其是在标签数量较多的情况下。 .repo/repo/repo start firefly --all 的作用如下: 作用 .repo/repo/repo start firefly --all: 这个命令用于在所有项目中创建一个新的分支,名为 firefly。 --all 选项表示在所有管理的项目中都执行这个操作,而不仅仅是当前项目。
- 拉取远程库
repo init -u git@1.2.3.4/manifest.git -b 分支(指定manifest文件:repo init -u <manifest-repo-url> -m <your-manifest-file.xml>) repo start master --all(切换到master分支,不存在则创建) repo sync -c
- 修改并提交
repo status repo add <filename> repo commit -m "" repo upload
- manifest示例
<?xml version="1.0" encoding="UTF-8"?> <manifest> <!-- 注意url的写法,要写全ssh://或http://,可能跟git clone的url有点区别,注意转换 --> <remote fetch="ssh://url" name="gitlab"/> <default remote="gitlab" revision="master" sync-j="8" /> <!-- 创建脚本链接,非必须 --> <project name="build" path="build" revision="master"> <linkfile dest="build.sh" src="build.sh" /> </project> <!-- 配置文件链接,非必须 --> <project name="config" path="config" revision="master"> <linkfile dest="test.json" src="test.json" /> </project> <!-- 测试模块 --> <project name="test" path="test" revision="master"/> </manifest>
# 1.初始化 repo init -u git@url/manifest.git -b dev # 2. 切换至master分支 repo start master --all # 3. 同步代码 repo sync -c # 如果不同工程分支不一样可使用以下脚本代替步骤:2、3 #!/bin/bash declare -A branches branches=( ["test1"]="dev" ["test2"]="feature/audio" ["test3"]="feature/event" ["test4"]="dev" ["test5"]="master" ) repo sync -c for project in "${!branches[@]}"; do if [ -d "$project" ]; then cd "$project" || continue current_branch=$(git rev-parse --abbrev-ref HEAD) if [ "$current_branch" != "${branches[$project]}" ]; then git checkout "${branches[$project]}" fi cd .. else echo "$project not exist!" exit 1 fi done
- repo进阶命令
repo status repo start my_branch --all repo forall -c 'git branch' repo branches repo forall -c 'git add . && git commit -m "提交说明"' repo forall -c 'git push' repo forall -c 'git push gitlab HEAD'(推送新分支) repo forall -c 'git log --oneline' repo forall -c 'git checkout <commit_hash>' repo manifest -r > my_manifes.xml 记录当版本到manifest xml文件 repo init -m /path/to/my_manifest.xml(绝对路径) # 同步所有仓库 repo sync # 同步特定的分支 repo sync branch_name # 同步特定的标签 repo sync --tags 另外:repo upload