谷歌仓库管理工具repo

Google 的仓库管理工具 Repo 是一个用于管理包含多个 Git 仓库的大型项目的命令行工具。它最初由 Google 为 Android 操作系统开发,以简化和协调众多子项目的版本控制和协作过程。以下是对 Repo 的详细解释:

主要功能与特点

  1. 多仓库管理
    Repo 能够同时管理成百甚至上千个 Git 仓库,这对大型项目尤为重要。通过统一的工具,开发者可以方便地同步、更新和维护所有相关的子仓库。

  2. Manifest 文件
    Repo 使用一个称为 Manifest 的 XML 文件来描述项目中所有的 Git 仓库,包括每个仓库的 URL、分支、路径以及依赖关系。Manifest 文件提供了一种集中管理仓库配置的方式,便于版本控制和团队协作。

  3. 统一操作命令
    使用 Repo,开发者可以通过简洁的命令对所有相关仓库执行操作。例如:

    • repo init:初始化 Repo 并下载 Manifest 文件。
    • repo sync:同步所有仓库到最新的提交。
    • repo status:查看所有仓库的当前状态。
    • repo checkout:切换所有仓库到指定的分支或标签。
  4. 分支和版本管理
    Repo 支持在多个仓库中一致地创建和切换分支,确保整个项目在不同开发阶段的一致性。这对于需要在不同功能或版本之间切换的项目尤为重要。

    Repo 提供了一个命令可以遍历所有项目并执行指定的 Git 命令。可以利用这个特性来检查每个子仓库的当前分支:
    repo forall -c 'echo $REPO_PATH: $(git rev-parse --abbrev-ref HEAD)'

  5. 扩展性和自定义
    Repo 是基于 Python 开发的,具有良好的可扩展性。开发者可以编写自定义脚本或插件,扩展 Repo 的功能以满足特定需求。

使用场景

  • Android 开发
    由于 Android 操作系统涉及众多子项目和组件,Repo 成为了管理这些复杂依赖关系的理想工具。

基本使用步骤

  1. 安装 Repo

    curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    chmod a+x ~/bin/repo
    
  2. 初始化仓库

    repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b <branch> --depth=1 --no-tags
    repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android13-release --depth=1 --no-tags
    

    –no-tags 参数可以避免下载所有标签
    –depth=1 参数表示只获取最近的一次提交

    这里使用了清华的镜像: https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest

  3. 同步仓库

    repo sync -c -j16  --no-tags
    

    -c 仅同步当前分支
    –no-tags 参数可以避免下载所有标签

  4. 常用命令

    • 查看状态:repo status
    • 从服务器提取当前的分支: repo sync -c -j8
    • 创建新分支:repo start <branch-name> --all
    • 提交更改:repo upload
  5. 减少repo的大小

  • 使用 repo forall 命令对每个仓库执行 git gc --prune=now --aggressive。可以使用以下命令:
    repo forall -c 'git gc --prune=now --aggressive'
To make edits to changes after they have been uploaded, you should use a tool like git rebase -i or git commit --amend to update your local commits. After your edits are complete: Make sure the updated branch is the currently checked out branch. For each commit in the series, enter the Gerrit change ID inside the brackets: # Replacing from branch foo [ 3021 ] 35f2596c Refactor part of GetUploadableBranches to lookup one specific... [ 2829 ] ec18b4ba Update proto client to support patch set replacments # Insert change numbers in the brackets to add a new patch set. # To create a new change record, leave the brackets empty. After the upload is complete the changes will have an additional Patch Set. If you only want to upload the currently checked out Git branch, you can use the flag --current-branch (or --cbr for short). diff repo diff [<PROJECT_LIST>] Shows outstanding changes between commit and working tree using git diff. download repo download <TARGET> <CHANGE> Downloads the specified change from the review system and makes it available in your project's local working directory. For example, to download change 23823 into your platform/build directory: repo download platform/build 23823 A repo sync should effectively remove any commits retrieved via repo download. Or, you can check out the remote branch; e.g., git checkout m/master. Note: There is a slight mirroring lag between when a change is visible on the web in Gerrit and when repo download will be able to find it for all users, because of replication delays to all servers worldwide. forall repo forall [<PROJECT_LIST>] -c <COMMAND> Executes the given shell command in each project. The following additional environment variables are made available by repo forall: REPO_PROJECT is set to the unique name of the project. REPO_PATH is the path relative to the root of the client. REPO_REMOTE is the name of the remote system from the manifest. REPO_LREV is the name of the revision from the manifest, translated to a local tracking branch. Used if you need to pass the manifest revision to a locally executed git command. REPO_RREV is the name of the revision from the manifest, exactly as written in the manifest. Options: -c: command and arguments to execute. The command is evaluated through /bin/sh and any arguments after it are passed through as shell positional parameters. -p: show project headers before output of the specified command. This is achieved by binding pipes to the command's stdin, stdout, and sterr streams, and piping all output into a continuous stream that is displayed in a single pager session. -v: show messages the command writes to stderr. prune repo prune [<PROJECT_LIST>] Prunes (deletes) topics that are already merged. start repo start <BRANCH_NAME> [<PROJECT_LIST>] Begins a new branch for development, starting from the revision specified in the manifest. The <BRANCH_NAME> argument should provide a short description of the change you are trying to make to the projects.If you don't know, consider using the name default. The <PROJECT_LIST> specifies which projects will participate in this topic branch. Note: "." is a useful shorthand for the project in the current working directory. status repo status [<PROJECT_LIST>] Compares the working tree to the staging area (index) and the most recent commit on this branch (HEAD) in each project specified. Displays a summary line for each file where there is a difference between these three states. To see the status for only the current branch, run repo status. The status information will be listed by project. For each file in the project, a two-letter code is used: In the first column, an uppercase letter indicates how the staging area differs from the last committed state. letter meaning description - no change same in HEAD and index A added not in HEAD, in index M modified in HEAD, modified in index D deleted in HEAD, not in index R renamed not in HEAD, path changed in index C copied not in HEAD, copied from another in index T mode changed same content in HEAD and index, mode changed U unmerged conflict between HEAD and index; resolution required In the second column, a lowercase letter indicates how the working directory differs from the index. letter meaning description - new/unknown not in index, in work tree m modified in index, in work tree, modified d deleted in index, not in work tree Was this page helpful? Let us know how we did:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值