repo 工具使用手册

安全漏洞 专栏收录该内容
14 篇文章 3 订阅

0x00 前言

该说点什么好呢,看到这个系列的第一篇的时间戳,已经是2年前了,生活总是这样要温故知新。安卓的项目已经从30个G变成了40多G,完全就是一个monstor一样的进化过程,不得不承认,能维护这么庞大的开源代码,是一件很不可思议的事情。

前一段时间微软宣布放弃edge浏览器内核的开发,准备启用chrome内核,一方面说明浏览器的复杂程度已经超出了自己预期成本,另一方面体现了开源项目的生命力。

0x01 repo工具

需求:在一个项目中包含了很多git仓库,一旦想更新代码,岂不是要到每个git目录下分别pull一遍代码?

当然,快捷的方式是写一个shell脚本,一键pull多个仓库。

repo就是这样的增强版工具。Google使用Python脚本统一管理多个git仓库,用于下载,回退版本等操作。

0x02 安装repo

工具比较小,而且没啥更新,直接用国内的即可。

创建工具所在bin目录

mkdir ~/bin

向zsh导入执行路径

比较习惯使用oh-my-zsh,所以需到在~/.zshrc中添加一句

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
  export ZSH="/home/counsellor/.oh-my-zsh"

export PATH=~/bin:$PATH # 这句是自己加的

下载repo

国内下载地址(推荐)

curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo

异世界下载地址

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

增加执行权限

chmod a+x ~/bin/repo

0x03 repo init

repo init的过程主要是下载一堆manifest配置文件,项目的remote url,项目包含的所有git仓库的地址,项目的版本等等。

建立工作目录

mkdir aosp
cd aosp

初始化仓库

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest

如果需要某个特定的 Android 版本(列表):

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-9.0.0_r30

在这里插入图片描述

真 · 初始化

repo init --depth=1 -u https://aosp.tuna.tsinghua.edu.cn/platform/manifestt -b android-9.0.0_r30

--depth=1 表示只下载最近版本的代码,只保留最近的commit版本。

使用--depth 可以节省本地磁盘空间,加速下载,对于开发够用了。

0x04 repo sync

他喵的,我初始化的时候指定了android -4的版本,结果发现同步过程有android-9.0.0的日志,down了3天3夜,140多G还没有同步完,眼泪哗哗的。

同步命令

repo sync

多线程并发同步

特步 - 飞一般的感觉

repo sync -j`nproc`

-j 参数指定同时运行多少个job,nproc是当前计算机的处理单元个数

这个命令的完整意思就是,开足马力,带你飞。

真 · 同步

repo sync -c -f --no-tags --no-clone-bundle -j`nproc`

-c 或者--current-branch表示只拉取当前分支代码,坑爹啊,我在init指定了分支,同步的时候,你却悄悄给我拉些没用的。
--no-tags 不拉取tags,tag虽然不大,但架不住多
--no-clone-bundle 不使用clone.bundle,clone.bundle是git bundle一样的打包文件,使用bundle文件可以做cdn下载的分流,cdn听上去不错,但是如果cdn到google的服务器,或者clone.bundle本来就占空间,不是很划算,所以不使用clone.bundle
-f 如果sync失败,继续同步(想想当年LZ写了一个while循环解决同步失败终止问题的)
--force-sync 如果文件目录有差异,强制覆盖掉

sync 失败的时候,就能想到-f
在这里插入图片描述

0x05 repo回滚

repo sync -d 可以将所有git 仓库的HEAD重置为manifest文件的指定版本。同时,处于暂存或者修改的目录变化不会被重置。

当然,-d 重置版本的妙用就是回滚,结合以下命令,可以让被指飞的git仓库门,全部恢复成干净的代码。

repo sync -d
repo forall -c 'git reset --hard'    # Remove all working directory (and staged) changes.
repo forall -c 'git clean -f -d'     # Clean untracked files

0x06 小结

  • repo主要用到两个功能,一个是init项目,另一个是下载项目;
  • AOSP项目本身很庞大,为了节约空间,尽量关注一个版本的代码比较好;
  • repo的本质是git,所以是可以使用代理【传送门】下载asop的。

0x07 参考文献

https://github.com/zawzaww/aosp-android
https://blog.csdn.net/zerooffdate/article/details/79348925
https://blog.csdn.net/u012842255/article/details/68941379
https://stackoverflow.com/questions/23300245/what-to-do-about-curl-clone-bundle-error-on-aosp-repo-sync
https://blog.csdn.net/mmh19891113/article/details/78476580
http://www.mashangxue123.com/git/3727190879.html
https://www.git-tower.com/learn/git/faq/detached-head-when-checkout-commit

  • 8
    点赞
  • 0
    评论
  • 48
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

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:
©️2021 CSDN 皮肤主题: 点我我会动 设计师:白松林 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值