Linux repo基本用法: 搭建自己的repo仓库[服务端]

news/2025/2/5 22:08:11/

在这里插入图片描述

概述

Repo的使用离不开Git, Git 和 Repo 都是版本控制工具,但它们在使用场景和功能上有明显区别…

Git

  1. 定义:Git 是一个分布式的版本控制系统,由 Linus Torvalds 为 Linux 内核开发而设计,现已成为世界上最流行的版本控制软件之一。
  2. 功能:Git 能够高效地追踪文件和目录的历史变更,支持分支和合并、提交历史记录、回滚更改、解决冲突等功能。它允许开发者在本地创建仓库并进行完整的版本控制操作,包括克隆、添加、提交、推送、拉取、合并等。

Repo

  1. 定义:Repo 是 Google 开发的一个高级工具,它是基于 Python 编写的一个脚本集合,主要用来管理和协调多个 Git 仓库的工作。
  2. 功能:Repo 主要针对大型项目,特别是那些包含了大量相互依赖的子模块或者子项目的工程,如 Android 开源项目 (AOSP)。Repo 可以简化对这些子仓库的初始化、同步、分支管理、提交以及推送等操作。它通过 manifest 文件来描述所有子项目的配置和依赖关系,从而提供了一种在顶层统一管理多个 Git 仓库的方法。

总的来说,

  • Git 是单个项目的版本控制系统。
  • Repo 是在 Git 之上构建的工具,用于大规模分布式开发环境中的多仓库协同管理。

使用 Repo 的好处在于能够方便地同时处理和同步多个相关联的 Git 仓库,简化复杂项目中跨仓库的日常版本控制任务。

使用REPO

国内的环境建议用mirrors.tuna.tsinghua.edu.cn 镜像

  • 下载

    curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o ~/bin/repo
    chmod +x repo
    

    为了方便可以将其拷贝到你的PATH里。

    更新

    repo的运行过程中会尝试访问官方的git源更新自己,如果想使用tuna的镜像源进行更新,可以将如下内容复制到你的~/.bashrc

    export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'

    并重启终端模拟器。

  • 同步/更新

    repo sync [project0 project1 ... projectn]
    repo sync [/path/to/project0 ... /path/to/projectn]
    
  • 初始化/init

    repo init -u url [options]
    

    在当前目录中安装 Repo。此命令会创建一个 .repo/ 目录,其中包含存放 Repo 源代码和标准 Android 清单文件的 Git 代码库。

    选项:

    • u:指定从中检索清单代码库的网址。常见清单位于 https://android.googlesource.com/platform/manifest
    • m:选择代码库中的清单文件。如果未选择清单名称,则默认为 default.xml
    • b:指定修订版本,即特定的 manifest-branch

    注意对于所有剩余的 Repo 命令,当前的工作目录必须是 .repo/ 的父目录或该父目录的子目录。

    当输入空的URL初始化, 报错. python 改为 python3 即可

    
    ubuntu@SERVER4:/disk4/repoTest$ repo init
    Downloading Repo source from https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
    remote: Enumerating objects: 8731, done.
    remote: Counting objects: 100% (4959/4959), done.
    remote: Compressing objects: 100% (2487/2487), done.
    remote: Total 8731 (delta 4744), reused 2472 (delta 2472), pack-reused 3772
    Receiving objects: 100% (8731/8731), 3.01 MiB | 4.60 MiB/s, done.
    Resolving deltas: 100% (6011/6011), done.
    Traceback (most recent call last):File "/home/user/bin/repo", line 1490, in <module>main(sys.argv[1:])File "/home/user/bin/repo", line 1440, in main_Init(args, gitc_init=(cmd == "gitc-init"))File "/home/user/bin/repo", line 691, in _Initos.rename(dst, dst_final)
    OSError: [Errno 39] Directory not empty: '/disk4/repoTest/.repo/repo.tmp' -> '/disk4/repoTest/.repo/repo'
    

搭建Repo仓库(服务端)

  1. 搭建基于gitolite的GIT服务器 192.168.7.3
  2. 默认创建的几个git仓库
    • 2.1. gitolite-admin : 用于管理git仓库和用户秘钥 [自动创建]

    • 2.2. manifest: 特殊Git仓库, repo通过此项目来获取仓库, 它包含了项目的清单(manifest)文件。仓库任意名称[手动创建]

      default.xml 或者 manifest.xml 这是最重要的文件之一,定义了项目树状结构、各个子项目的URL、分支、标签以及其他同步策略等信息。每个项目对应一个 <project> 标签,并且包含项目路径、git仓库URL等属性

      groups.xml:可能存在的文件,用于定义不同的项目组,以便于根据开发团队的不同需求或者权限来下载不同的子项目集合。

      other-manifests/ 目录: 该目录下可能有多个针对不同构建目标或版本的manifest文件,如 android-9.0.0.xml 等。

    • 2.3. test: 测试项目 [自动创建]

  3. 配置repo的manifest: 只需要一个文件- default.xml
    • default.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <manifest><remote name="codes" fetch="."/><default remote="codes" sync-j="4"/><project name="project_1" revision="master"/><project name="project_2" revision="master"/>
      </manifest>
      

      manifest文件定义了这些仓库的基本布局和同步规则。配置含义如下:

  • <remote name="codes" fetch="."/>:定义了一个远程仓库,名字叫做codes,其fetch地址为.。这里的.代表当前目录,意味着所有的项目都位于本地同一个父目录下,不需要从远程服务器拉取代码。
  • <default remote="codes" sync-j="4"/>:设置默认的远程仓库为刚刚定义的codes,并且设置了sync-j属性为4,这意味着在执行repo sync命令时,将会并发运行4个jobs(任务)来并行拉取和更新各个项目。
  • <project name="project_1" revision="master"/>:定义了一个名为project_1的项目,其对应的Git仓库的分支或者提交哈希为master,repo会在同步时检查并确保该项目处于master分支的最新状态。
  • <project name="project_2" revision="master"/>:类似地,定义了另一个名为project_2的项目,同样指向master分支。

      文件描述了一个由两个Git项目(project_1project_2)组成的代码仓库集合,它们都将从本地的codes远程仓库同步,并且在同步时默认使用master分支,并且同步过程可以并发执行四个任务以提高效率。

  1. 客户端下载同步
    刚开始使用的文件名称: manifest, 导致报错: 'default.xml’ not available
        Downloading Repo source from https://mirrors.tuna.tsinghua.edu.cn/git/git-reporemote: Enumerating objects: 8731, done.remote: Counting objects: 100% (4959/4959), done.remote: Compressing objects: 100% (2487/2487), done.remote: Total 8731 (delta 4745), reused 2472 (delta 2472), pack-reused 3772Receiving objects: 100% (8731/8731), 3.01 MiB | 10.66 MiB/s, done.Resolving deltas: 100% (6012/6012), done.fatal: manifest 'default.xml' not availablefatal: manifest default.xml not found================================================================================Repo command failed: UpdateManifestErrorUnable to sync manifest default.xml

指定清单: repo init git@192.168.7.3:RepoTest -m other_manifest.xml

    #download manifestsubuntu@SERVER4:/disk4/repoTest$ repo init -u git@192.168.7.3:manifestrepo: reusing existing repo client checkout in /disk4/repoTestrepo has been initialized in /disk4/repoTest#repo sync download all sourceubuntu@SERVER4:/disk4/repoTest$ repo syncFetching: 100% (2/2), done in 14.816sUpdating files: 100% (1050/1050), done.Checking out: 100% (2/2), done in 5.283srepo sync has finished successfully.

附录(仅供参考)

服务端文件结构:

$ sudo ls -l /home/git/repositories/
total 172
drwx------ 7 git git 4096 219 15:14 project_1.git
drwx------ 7 git git 4096 219 15:14 project_2.git
drwx------ 7 git git 4096 219 15:14 RepoTest.git
drwx------ 7 git git 4096 219 15:14 manifest.git
drwx------ 7 git git 4096 219 15:14 test.git
$ tree RepoTest/RepoTest/├── other_manifest.xml└── default.xml

客户端文件

$ tree -L 1 -a RepoTest/RepoTest/├── project_1├── project_2└── .repo├── copy-link-files.json├── manifests│   ├── other_manifest.xml│   ├── default.xml│   └── .git -> ../manifests.git├── manifests.git├── manifest.xml├── project.list├── project-objects├── projects├── repo├── .repo_fetchtimes.json├── .repo_localsyncstate.json└── TRACE_FILE

常见错误

  • ‘NoneType’ object has no attribute 'rstrip’ : 检查manifest配置, 非python错误

    repo sync
    ================================================================================
    Repo command failed: RepoUnhandledExceptionError'NoneType' object has no attribute 'rstrip'
    

参考

repo使用总结—从入门到入门
Repo实践指南
repo:从零开始搭建repo环境
搭建支持 Repo 的 Android 源码镜像(Repo 服务器)


http://www.ppmy.cn/news/1405481.html

相关文章

云计算对象存储服务

对象存储服务&#xff08;OSS&#xff09;中的存储桶(Bucket)叫做‘OBS桶 存储桶&#xff08;Bucket&#xff09;&#xff1a;存储桶式对象存储服务中用于存储对象的基本容器&#xff0c;类似于文件系统中的文件夹。每个存储桶具有唯一的名称&#xff0c;并且可以在桶中存储任…

谈谈你对 ES6 的理解

es6 是一个新的标准&#xff0c;它包含了许多新的语言特性和库&#xff0c;是 JS 最实质性的一次升级。 比如箭头函数、字符串模板、generators(生成器)、async/await、解构赋值、class等等&#xff0c;还有就是引入 module 模块的概念。 箭头函数可以让 this 指向固定化&…

计算机网络:数据链路层 - 点对点协议PPP

计算机网络&#xff1a;数据链路层 - 点对点协议PPP PPP协议的帧格式透明传输字节填充法零比特填充法 差错检测循环冗余校验 对于点对点链路&#xff0c;PPP协议是目前使用最广泛的数据链路层协议。比如说&#xff0c;当用户想要接入互联网&#xff0c;就需要通过因特网服务提供…

windows qt打包保姆级教学

windows qt打包保姆级教学 简述打包打包进阶 简述 在windows下开发的qt程序&#xff0c;想在其他windows计算机上运行&#xff0c;而那个计算机没有qt环境&#xff0c;执行时候会报错各种dll找不到&#xff0c;那么就需要将自己开发的qt程序和用到的库打包。 打包 这里先编译…

图论基础(python蓝桥杯)

图的基本概念 图的种类 怎么存放图呢&#xff1f; 优化 DFS 不是最快/最好的路&#xff0c;但是能找到一条连通的道路。&#xff08;判断两点之间是不是连通的&#xff09; 蓝桥3891 import os import sys sys.setrecursionlimit(100000) # 请在此输入您的代码 n, m map(int,…

基于单片机按键控制看门狗仿真设计

**单片机设计介绍&#xff0c;基于单片机按键控制看门狗仿真设计 文章目录 一 概要二、功能设计三、 软件设计原理图 五、 程序六、 文章目录 一 概要 基于单片机按键控制看门狗仿真设计概要主要涉及利用单片机上的按键来控制看门狗的功能&#xff0c;从而实现系统故障的及时检…

LeetCode-146. LRU 缓存【设计 哈希表 链表 双向链表】

LeetCode-146. LRU 缓存【设计 哈希表 链表 双向链表】 题目描述&#xff1a;解题思路一&#xff1a;双向链表&#xff0c;函数 get 和 put 必须以 O(1) 的平均时间复杂度运行。一张图&#xff1a;知识点__slots__ 解题思路二&#xff1a;0解题思路三&#xff1a;0 题目描述&am…

Maven入门指南:构建与管理Java项目的利器

引言 在Java开发领域&#xff0c;项目构建和管理是一个至关重要的环节。随着项目规模和复杂度的不断增加&#xff0c;有效地管理项目的依赖、构建过程以及部署流程变得尤为关键。在这样的背景下&#xff0c;Apache Maven作为一款优秀的项目管理工具应运而生&#xff0c;成为了…