博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
搭建repo服务器管理多个git工程
阅读量:4125 次
发布时间:2019-05-25

本文共 8503 字,大约阅读时间需要 28 分钟。

搭建repo服务器管理多个git工程

原文链接: or

1.repo介绍

android使用git作为代码管理工具,开发了gerrit进行代码审核以便更好的对代码进行集中式管理。还开发了repo命令行工具,对git部分命令进行封装,将百多个git库有效的组织。

鉴于repo能够管理多个git库,针对一个项目需要多个git库分开管理使用repo就非常方便。如嵌入式项目一般由uboot、kernel、文件系统rootfs、用户程序等组成。这里就以这样的项目组织来搭建repo服务器。

├── kernel│   └── linux-3.5.y├── rootfs│   └── rootfs├── uboot│   └── uboot-2018.11└── userdata    └── UartTest

服务器:192.168.3.5

账户:git

2.下载repo

git-repo下载可在服务器端通过以下任一方式下载。

git clone https://gerrit.googlesource.com/git-repo		(谷歌官方源)git clone https://mirrors.tuna.tsinghua.edu.cn/git/git-repo	(国内清华源)git clone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo	(国内中科大源)

3.初始化工程和mainifest git仓库

3.1 初始化项目代码仓库 git server端

git@lisongze-virtual-machine:~$ mkdir exynos4412git@lisongze-virtual-machine:~$ mkdir -p exynos4412/platform/kernel/linux-3.5.y.gitgit@lisongze-virtual-machine:~$ mkdir -p exynos4412/platform/uboot/uboot-2018.11.gitgit@lisongze-virtual-machine:~$ mkdir -p exynos4412/platform/rootfs/rootfs.gitgit@lisongze-virtual-machine:~$ mkdir -p exynos4412/platform/userdata/UartTest.gitgit@lisongze-virtual-machine:~$ cd exynos4412/platform/kernel/linux-3.5.y.gitgit@lisongze-virtual-machine:~/exynos4412/platform/kernel/linux-3.5.y.git$ git init --bare已初始化空的 Git 仓库于 /home/git/exynos4412/platform/kernel/linux-3.5.y.git/git@lisongze-virtual-machine:~/exynos4412/platform/uboot/uboot-2018.11.git$ cdgit@lisongze-virtual-machine:~$ cd exynos4412/platform/uboot/uboot-2018.11.gitgit@lisongze-virtual-machine:~/exynos4412/platform/uboot/uboot-2018.11.git$ git init --bare已初始化空的 Git 仓库于 /home/git/exynos4412/platform/uboot/uboot-2018.11.git/git@lisongze-virtual-machine:~/exynos4412/platform/uboot/uboot-2018.11.git$ cdgit@lisongze-virtual-machine:~$ cd exynos4412/platform/rootfs/rootfs.gitgit@lisongze-virtual-machine:~/exynos4412/platform/rootfs/rootfs.git$ git init --bare已初始化空的 Git 仓库于 /home/git/exynos4412/platform/rootfs/rootfs.git/git@lisongze-virtual-machine:~/exynos4412/platform/rootfs/rootfs.git$ cdgit@lisongze-virtual-machine:~$ cd exynos4412/platform/userdata/UartTest.gitgit@lisongze-virtual-machine:~/exynos4412/platform/userdata/UartTest.git$ git init --bare已初始化空的 Git 仓库于 /home/git/exynos4412/platform/userdata/UartTest.git/git@lisongze-virtual-machine:~/exynos4412/platform/userdata/UartTest.git$ cd

3.2 初始化manifest仓库 git server端

3.2.1 初始化 manifest git server端

git@lisongze-virtual-machine:~$ mkdir -p exynos4412/platform/mainfest.gitgit@lisongze-virtual-machine:~$ cdgit@lisongze-virtual-machine:~/exynos4412/platform/mainfest.git$ git init --bare已初始化空的 Git 仓库于 /home/git/exynos4412/platform/mainfest.git/

3.2.2 mainfest 提交default.xml

git@lisongze-virtual-machine:~/exynos4412$ git clone git@192.168.3.5:~/exynos4412/platform/mainfest.git正克隆到 'mainfest'...git@192.168.3.5's password:warning: 您似乎克隆了一个空仓库。

default.xml

remote name:远程仓库名

revision:分支名

git@lisongze-virtual-machine:~/exynos4412/mainfest$ git add default.xmlgit@lisongze-virtual-machine:~/exynos4412/mainfest$ git comit -m "add default.xml"git@lisongze-virtual-machine:~/exynos4412/mainfest$ git push origin mster

3.3 客户端git提交初始代码

在客户端 192.168.3.xxx源码工程下提交初始代码推送到远程服务器下对应的git仓库。

//在exynos4412/kernel/linux-3.5.y下执行$ git init$ git add .$ git commit -m "Init Code"$ git push git@192.168.3.5:/home/git/exynos4412/platform/kernel/linux-3.5.y.git master//在exynos4412/rootfs/rootfs下执行$ git init$ git add .$ git commit -m "Init Code"$ git push git@192.168.3.5:/home/git/exynos4412/platform/rootfs/rootfs.git master//在exynos4412/uboot/uboot-2018.11下执行$ git init$ git add .$ git commit -m "Init Code"$ git push git@192.168.3.5:/home/git/exynos4412/platform/uboot/uboot-2018.11.git master//在exynos4412/exynos4412/userdata/UartTest下执行$ git init$ git add .$ git commit -m "Init Code"$ git push git@192.168.3.5:/home/git/exynos4412/platform/userdata/UartTest.git master

4. repo拉取工程代码

在客户端上repo拉取服务器端代码

repo 需要从git-repo源码中拷贝过来,修改url并加上执行权限chmod 777 repo。

  • 将REPO_URL = ‘’ 修改为 REPO_URL = ‘ssh://192.168.3.5/home/git/tools/git-repo’

如有fatal: branch ‘stable’ has not been signed报错,可将REPO_REV = ‘stable’ 改为 REPO_REV = ‘master’,或着可在git-repo源码中切换到stable分支,git check -b state remote/origin/stable,也可重新获取state分支 git clone -b state

$ mkdir exynos4412_code$ cd exynos4412_code$ ./repo init -u git@192.168.3.5:/home/git/exynos4412/platform/manifest.git$ ./repo sync

5. repo创建分支

在项目中我们经常会基于某分支新建分支,来开发新的项目。这里我们演示基于master分支创建tiny4412_evb新分支。

5.1 客户端创建分支并推送远程仓库

./repo forall -pv -c "git checkout remotes/m/master -B tiny4412_evb"./repo forall -pv -c "git push linux tiny4412_evb"

推送远程仓库

git push [remote-name] [branch-name]

  • remote-name:远程仓库名(一般默认远程分支名称为origin)
  • branch-name: 分支名称
    这里远程分支为linux,是由于在default.xml中定义的。

其中会报两个错误,是由于没有权限导致,如下

error: unpack failed: unable to create temporary object directory
remote: error: cannot lock ref ‘refs/heads/tiny4412_evb’: 不能创建 '/home/git/exynos4412/platform/
解决方法比较暴力,到对应的git服务器端chmod 777 -R object 和 chmod 777 -R refs

5.2 修改远端服务端manifest

git@lisongze-virtual-machine:~/exynos4412/manifest$ git branch -a* master  remotes/origin/mastergit@lisongze-virtual-machine:~/exynos4412/manifest$ git checkout -b tiny4412_evb remotes/origin/master分支 'tiny4412_evb' 设置为跟踪来自 'origin' 的远程分支 'master'。切换到一个新分支 'tiny4412_evb'git@lisongze-virtual-machine:~/exynos4412/manifest$ vim default.xmlgit@lisongze-virtual-machine:~/exynos4412/manifest$ git diffdiff --git a/default.xml b/default.xmlindex d1aeaa7..d790a73 100644--- a/default.xml+++ b/default.xml@@ -2,7 +2,7 @@ 
-
git@lisongze-virtual-machine:~/exynos4412/manifest$ git add default.xmlgit@lisongze-virtual-machine:~/exynos4412/manifest$ git commit -m "add new branch tiny4412_evb"[tiny4412_evb 25d1cf6] add new branch tiny4412_evb 1 file changed, 1 insertion(+), 1 deletion(-)git@lisongze-virtual-machine:~/exynos4412/manifest$ git push origin tiny4412_evbgit@192.168.3.5's password:对象计数中: 3, 完成.Delta compression using up to 4 threads.压缩对象中: 100% (2/2), 完成.写入对象中: 100% (3/3), 293 bytes | 293.00 KiB/s, 完成.Total 3 (delta 1), reused 0 (delta 0)To 192.168.3.5:~/exynos4412/platform/manifest.git * [new branch] tiny4412_evb -> tiny4412_evb

5.3 拉取新建分支代码

mkdir tiny4412_evbcd tiny4412_evb./repo init -u git@192.168.3.5:/home/git/exynos4412/platform/manifest.git -b tiny4412_evb./repo sync

6. 增加子工程git管理

经常我们需要增加一个单独的子工程需要用git管理,就需要修改远端服务器。

6.1 服务器侧操作—创建目录初始化git server

git@lisongze-virtual-machine:~$ mkdir -p exynos4412/platform/rootfs/tslib.gitgit@lisongze-virtual-machine:~$ cd exynos4412/platform/rootfs/tslib.gitgit@lisongze-virtual-machine:~$ git init --bare

6.2 客户端操作-提交代码

这里我示例增加rootfs/tslib源码,在tiny4412_evb分支上。

在tiny4412_evb目录下操作,拷贝tslib源码到rootfs下

./repo forall -pv -c "git checkout -b tiny4412_evb remotes/linux/tiny4412_evb"cd rootfs/tslib/git initgit add .git commit -m "add tslib code"git branch tiny4412_evbgit checkout tiny4412_evbgit push git@192.168.3.5:/home/git/exynos4412/platform/rootfs/tslib.git tiny4412_evb

6.3 服务器侧操作-修改manifest

git@lisongze-virtual-machine:git checkout -B tiny4412_evb remotes/origin/tiny4412_evbgit@lisongze-virtual-machine:~/exynos4412/manifest$ git branch  master* tiny4412_evbgit@lisongze-virtual-machine:~/exynos4412/manifest$ git diffdiff --git a/default.xml b/default.xmlindex d790a73..9cb1d41 100644--- a/default.xml+++ b/default.xml@@ -8,6 +8,7 @@   
+
git@lisongze-virtual-machine:~/exynos4412/manifest$ git add default.xmlgit@lisongze-virtual-machine:~/exynos4412/manifest$ git status位于分支 tiny4412_evb您的分支与上游分支 'origin/tiny4412_evb' 一致。要提交的变更: (使用 "git reset HEAD
<文件>
..." 以取消暂存) 修改: default.xmlgit@lisongze-virtual-machine:~/exynos4412/manifest$ git commit -m "add tslib"[tiny4412_evb 740d86f] add tslib 1 file changed, 1 insertion(+)git@lisongze-virtual-machine:~/exynos4412/manifest$ git push origin tiny4412_evbgit@192.168.3.5's password:对象计数中: 3, 完成.Delta compression using up to 4 threads.压缩对象中: 100% (2/2), 完成.写入对象中: 100% (3/3), 307 bytes | 307.00 KiB/s, 完成.Total 3 (delta 1), reused 0 (delta 0)To 192.168.3.5:~/exynos4412/platform/manifest.git 25d1cf6..740d86f tiny4412_evb -> tiny4412_evb

提交完验证

./repo init -u git@192.168.3.5:/home/git/exynos4412/platform/manifest.git -b tiny4412_evb./repo sync

7. 给整个工程打tag标签

git打tag命令:

git tag –a TAG_NAME -m "add tag TAG_NAME"

我们在此版本上打上标签为TINY4412_V1.0.0,命令如下

./repo sync./repo forall -pv -c "git tag -a TINY4412_V1.0.0 -m "add tag TINY4412_V1.0.0""./repo forall -pv -c "git push linux TINY4412_V1.0.0"

总结

通过上面方法创建repo服务器,可以看出简单的项目工程还是可以手动创建,但较复杂的工程,如android还是比较麻烦,最好的方式就是通过sh脚本来实现。但原理是相通的,repo 管理一个项目有多个git仓库有强大的优势的。

转载地址:http://nglpi.baihongyu.com/

你可能感兴趣的文章
一步步开发 Spring MVC 应用
查看>>
python: extend (扩展) 与 append (追加) 的差别
查看>>
「译」在 python 中,如果 x 是 list,为什么 x += "ha" 可以运行,而 x = x + "ha" 却抛出异常呢?...
查看>>
浅谈JavaScript的语言特性
查看>>
LeetCode第39题思悟——组合总和(combination-sum)
查看>>
LeetCode第43题思悟——字符串相乘(multiply-strings)
查看>>
LeetCode第44题思悟——通配符匹配(wildcard-matching)
查看>>
LeetCode第45题思悟——跳跃游戏(jump-game-ii)
查看>>
LeetCode第46题思悟——全排列(permutations)
查看>>
LeetCode第47题思悟—— 全排列 II(permutations-ii)
查看>>
LeetCode第48题思悟——旋转图像(rotate-image)
查看>>
驱动力3.0,动力全开~
查看>>
记CSDN访问量10万+
查看>>
Linux下Oracle数据库账户被锁:the account is locked问题的解决
查看>>
记CSDN访问20万+
查看>>
Windows 环境下Webstorm 2020.3 版本在右下角找不到Git分支切换部件的一种解决方法
查看>>
Electron-Vue项目中遇到fs.rm is not a function问题的解决过程
查看>>
飞机换乘次数最少问题的两种解决方案
查看>>
有向无回路图的理解
查看>>
设计模式中英文汇总分类
查看>>