本文共 8503 字,大约阅读时间需要 28 分钟。
原文链接: or
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
账户:gitgit-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 (国内中科大源)
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
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/
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
在客户端 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
在客户端上repo拉取服务器端代码
repo 需要从git-repo源码中拷贝过来,修改url并加上执行权限chmod 777 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
在项目中我们经常会基于某分支新建分支,来开发新的项目。这里我们演示基于master分支创建tiny4412_evb新分支。
./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]
其中会报两个错误,是由于没有权限导致,如下
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 refsgit@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
mkdir tiny4412_evbcd tiny4412_evb./repo init -u git@192.168.3.5:/home/git/exynos4412/platform/manifest.git -b tiny4412_evb./repo sync
经常我们需要增加一个单独的子工程需要用git管理,就需要修改远端服务器。
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
这里我示例增加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
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
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/