git-repo git-repo
是 Google 推出的管理多个 git 项目 的工具,主要被运用在 Android 系统源码的管理上。
国内访问不了 Google,repo 版本可以选择 Github 上的优化版本:git-repo
安装 1 2 curl https://raw.githubusercontent.com/esrlabs/git-repo/stable/repo > ~/bin/repo chmod a+x ~/bin/repo
基本操作 初始化 1 repo init -u [url] -b [branch]
同步
开始 1 2 repo start [branch] --all
查看分支
基于 Github 实现 repo 控制多个项目 repo 工作原理 第一步repo init
的时候我们需要提供一个url ,这个url 是个清单工程,工程中包含一个xml 文件,指定了其他项目的路径,repo sync
的时候通过这个xml ,去下载各个项目。
编写 manifest.xml default.xml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?xml version="1.0" encoding="UTF-8" ?> <manifest > <remote name ="origin" fetch ="https://github.com/gavinliu/" review ="https://github.com/gavinliu/" /> <default revision ="master" remote ="origin" sync-j ="4" /> <project path ="BeautifulOfSin" name ="BeautifulOfSin" /> <project path ="BeautifulOfBezier" name ="BeautifulOfBezier" /> </manifest >
创建 manifest 工程 gavinliu/manifest ,添加 default.xml
测试体验 1.初始化 1 2 3 4 5 6 7 8 9 10 11 12 13 $ mkdir MyGithub $ cd MyGithub $ repo init -u git@github.com:gavinliu/manifest.git -b master Get git@github.com:gavinliu/manifest.git remote: Counting objects: 4, done . remote: Compressing objects: 100% (3/3), done . remote: Total 4 (delta 0), reused 4 (delta 0), pack-reused 0 From github.com:gavinliu/manifest * [new branch] master -> origin/master Your identity is: 刘云龙 <gavin6liu@gmail.com> If you want to change this, please re-run 'repo init' with --config-name repo has been initialized in /Users/Gavin/MyGithub
2.同步 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 $ repo sync Fetching project BeautifulOfSin Fetching project BeautifulOfBezier remote: Counting objects: 77, done . remote: Compressing objects: 100% (44/44), done . remote: Counting objects: 133, done . remote: Total 133 (delta 0), reused 0 (delta 0), pack-reused 133 Receiving objects: 100% (133/133), 38.84 KiB | 0 bytes/s, done . Resolving deltas: 100% (39/39), done . From https://github.com/gavinliu/BeautifulOfBezier * [new branch] master -> origin/master Fetching projects: 50% (1/2) remote: Total 77 (delta 11), reused 77 (delta 11), pack-reused 0 From https://github.com/gavinliu/BeautifulOfSin * [new branch] master -> origin/master
3.切分支 1 2 3 4 $ repo start master --all $ repo branches * master | in all projects
4.查看项目 1 2 3 4 5 6 7 8 9 10 11 12 $ ll total 0 drwxr-xr-x 8 Gavin staff 272 4 15 22:39 BeautifulOfBezier drwxr-xr-x 9 Gavin staff 306 4 15 22:39 BeautifulOfSin $ cd BeautifulOfBezier $ git status On branch master Your branch is up-to-date with 'origin/master' . nothing to commit, working directory clean
最后查看各个项目,都已切换到 master 分支,代码也都是最新的,成功啦~
End 更多 repo 使用技巧,利用搜索引擎能找到很多资料,这里就不赘述啦。