服务端
本地搭建repo服务器的方法:
首先得确保本地的git能够正常使用,并下载一个repo可以正常运行
目录结构如下:
首先新建一个文件夹repo-server,并在其下新建两个目录,如上图所示
在manifest.git文件夹中执行 git init 初始化一个git 库并添加default.xml
其中比较重要的是manifest.git文件夹中的default.xml,该default.xml的内容如下:
其中fetch就是你在服务器端所在的位置,可以是远程的,也可以是本地的,我这里设置的是本地的
客户端与服务器同步就是依靠这个地址进行repo sync的
其中default标签是用来设置分支名和远端服务器默认名的
接下来的project标签就是你要通过repo来管理的git库位置了
添加完毕后执行git add -A添加到缓冲区,再通过git commit -m "Init"添加到仓库中去(这些都是基本的git操作,这里不做详述)
manifest.git的文件列表
project目录下git 项目建立
在project1目录下执行
git init
git add -A
git commit -m "project1 Init"
cd ..
git clone --bare project1 project1.git
查看project目录下,是否存在project1.git(project1的纯净仓库)
如果存在则删除 project1(服务端只保留git纯净仓库)
在project2目录下同样执行上述操作,获取project2.git
至此,服务端工作已经完成
客户端
在repo-client文件夹下执行
repo init -u server_path
这个server_path是default.xml所在的目录路径
我的server_path是/home/Neo/repo/repo-server/manifest.git
所以我应该执行:
repo init -u /home/Neo/repo/repo-server/manifest.git
如果提示下面的错误:
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno 101] Network is unreachable
这说明网络连接有问题,而你确认你网络没有问题的话,那就多连几次吧,会好的(G.F.W)
结果如下:
[root@SVR6 repo-client1]# repo init -u /home/Neo/repo/repo-server/manifest.git/
Get https://gerrit.googlesource.com/git-repo
remote: Counting objects: 197, done
remote: Finding sources: 100% (144/144)
remote: Getting sizes: 100% (24/24)
remote: Compressing objects: 100% (246848/246848)
remote: Total 2401 (delta 202), reused 2380 (delta 199)
Receiving objects: 100% (2401/2401), 1.48 MiB | 340 KiB/s, done.
Resolving deltas: 100% (1402/1402), done.
From https://gerrit.googlesource.com/git-repo
* [new branch] maint -> origin/maint
* [new branch] master -> origin/master
* [new branch] stable -> origin/stable
* [new tag] v1.0 -> v1.0
* [new tag] v1.0.1 -> v1.0.1
* [new tag] v1.0.2 -> v1.0.2
* [new tag] v1.0.3 -> v1.0.3
* [new tag] v1.0.4 -> v1.0.4
* [new tag] v1.0.5 -> v1.0.5
* [new tag] v1.0.6 -> v1.0.6
* [new tag] v1.0.7 -> v1.0.7
* [new tag] v1.0.8 -> v1.0.8
* [new tag] v1.0.9 -> v1.0.9
* [new tag] v1.1 -> v1.1
* [new tag] v1.10.0 -> v1.10.0
* [new tag] v1.10.1 -> v1.10.1
* [new tag] v1.10.2 -> v1.10.2
* [new tag] v1.10.3 -> v1.10.3
* [new tag] v1.10.4 -> v1.10.4
* [new tag] v1.11.0 -> v1.11.0
* [new tag] v1.11.1 -> v1.11.1
* [new tag] v1.12.0 -> v1.12.0
* [new tag] v1.12.1 -> v1.12.1
* [new tag] v1.12.2 -> v1.12.2
* [new tag] v1.2 -> v1.2
* [new tag] v1.3 -> v1.3
* [new tag] v1.3.1 -> v1.3.1
* [new tag] v1.3.2 -> v1.3.2
* [new tag] v1.4 -> v1.4
* [new tag] v1.4.1 -> v1.4.1
* [new tag] v1.4.2 -> v1.4.2
* [new tag] v1.4.3 -> v1.4.3
* [new tag] v1.4.4 -> v1.4.4
* [new tag] v1.5 -> v1.5
* [new tag] v1.5.1 -> v1.5.1
* [new tag] v1.6 -> v1.6
* [new tag] v1.6.1 -> v1.6.1
* [new tag] v1.6.10 -> v1.6.10
* [new tag] v1.6.10.1 -> v1.6.10.1
* [new tag] v1.6.10.2 -> v1.6.10.2
* [new tag] v1.6.2 -> v1.6.2
* [new tag] v1.6.3 -> v1.6.3
* [new tag] v1.6.4 -> v1.6.4
* [new tag] v1.6.5 -> v1.6.5
* [new tag] v1.6.6 -> v1.6.6
* [new tag] v1.6.7 -> v1.6.7
* [new tag] v1.6.7.1 -> v1.6.7.1
* [new tag] v1.6.7.2 -> v1.6.7.2
* [new tag] v1.6.7.3 -> v1.6.7.3
* [new tag] v1.6.7.4 -> v1.6.7.4
* [new tag] v1.6.7.5 -> v1.6.7.5
* [new tag] v1.6.8 -> v1.6.8
* [new tag] v1.6.8.1 -> v1.6.8.1
* [new tag] v1.6.8.10 -> v1.6.8.10
* [new tag] v1.6.8.11 -> v1.6.8.11
* [new tag] v1.6.8.2 -> v1.6.8.2
* [new tag] v1.6.8.3 -> v1.6.8.3
* [new tag] v1.6.8.4 -> v1.6.8.4
* [new tag] v1.6.8.5 -> v1.6.8.5
* [new tag] v1.6.8.6 -> v1.6.8.6
* [new tag] v1.6.8.7 -> v1.6.8.7
* [new tag] v1.6.8.8 -> v1.6.8.8
* [new tag] v1.6.8.9 -> v1.6.8.9
* [new tag] v1.6.9 -> v1.6.9
* [new tag] v1.6.9.1 -> v1.6.9.1
* [new tag] v1.6.9.2 -> v1.6.9.2
* [new tag] v1.6.9.3 -> v1.6.9.3
* [new tag] v1.6.9.4 -> v1.6.9.4
* [new tag] v1.6.9.5 -> v1.6.9.5
* [new tag] v1.6.9.6 -> v1.6.9.6
* [new tag] v1.6.9.7 -> v1.6.9.7
* [new tag] v1.6.9.8 -> v1.6.9.8
* [new tag] v1.7 -> v1.7
* [new tag] v1.7.1 -> v1.7.1
* [new tag] v1.7.2 -> v1.7.2
* [new tag] v1.7.3 -> v1.7.3
* [new tag] v1.7.3.1 -> v1.7.3.1
* [new tag] v1.7.4 -> v1.7.4
* [new tag] v1.7.4.1 -> v1.7.4.1
* [new tag] v1.7.4.2 -> v1.7.4.2
* [new tag] v1.7.4.3 -> v1.7.4.3
* [new tag] v1.7.5 -> v1.7.5
* [new tag] v1.7.6 -> v1.7.6
* [new tag] v1.7.6.1 -> v1.7.6.1
* [new tag] v1.7.7 -> v1.7.7
* [new tag] v1.7.7.1 -> v1.7.7.1
* [new tag] v1.7.7.2 -> v1.7.7.2
* [new tag] v1.7.7.3 -> v1.7.7.3
* [new tag] v1.7.7.4 -> v1.7.7.4
* [new tag] v1.7.7.5 -> v1.7.7.5
* [new tag] v1.7.7.6 -> v1.7.7.6
* [new tag] v1.7.8 -> v1.7.8
* [new tag] v1.7.8.1 -> v1.7.8.1
* [new tag] v1.7.8.2 -> v1.7.8.2
* [new tag] v1.8.0 -> v1.8.0
* [new tag] v1.8.1 -> v1.8.1
* [new tag] v1.8.2 -> v1.8.2
* [new tag] v1.9.0 -> v1.9.0
* [new tag] v1.9.1 -> v1.9.1
* [new tag] v1.9.2 -> v1.9.2
* [new tag] v1.9.3 -> v1.9.3
* [new tag] v1.9.4 -> v1.9.4
* [new tag] v1.9.5 -> v1.9.5
* [new tag] v1.9.6 -> v1.9.6
... A new repo command ( 1.19) is available.
... You should upgrade soon:
cp /home/Neo/repo/repo-client1/.repo/repo/repo /bin/repo
Get /home/Neo/repo/repo-server/manifest.git/
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/Neo/repo/repo-server/manifest
* [new branch] master -> origin/master
Your Name [root]:
添加完名字和邮件地址即可。
然后这个时候依旧没有代码,这是因为代码还只是存在git库中,需要执行repo syn
[root@SVR6 repo-client1]# repo sync
... A new repo command ( 1.19) is available.
... You should upgrade soon:
cp /home/Neo/repo/repo-client1/.repo/repo/repo /bin/repo
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/Neo/repo/repo-server/project/project1
* [new branch] master -> repo-server/master
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/Neo/repo/repo-server/project/project2
* [new branch] master -> repo-server/master
这时进入project/project1中时通过git branch查看的时候确是no branch..
[root@SVR6 project1]# git branch
* (no branch)
那是因为没有从确定所取的分支,执行
[root@SVR6 repo-client1]#repo forall -c git checkout -b master remotes/m/master
... A new repo command ( 1.19) is available.
... You should upgrade soon:
cp /home/Neo/repo/repo-client1/.repo/repo/repo /bin/repo
HEAD is now at 789317b... create project1
HEAD is now at 707deec... create project2
[root@SVR6 repo-client1]#
这里为什么会是remotes/m/master呢,这是需要查看下,你可以通过repo forall -c git branch -a
[root@SVR6 repo-client1]# repo forall -c git branch -a
... A new repo command ( 1.19) is available.
... You should upgrade soon:
cp /home/Neo/repo/repo-client1/.repo/repo/repo /bin/repo
* (no branch)
remotes/m/master -> repo-server/master
remotes/repo-server/master
* (no branch)
remotes/m/master -> repo-server/master
remotes/repo-server/master
#remotes/m/master是这个就是一个repo的清单库的分支,也就是当你在执行repo init -U [URL] -b [branch_name]的时候,-b参数后面的分支。如果你repo init的 时候,没有指定过-b参数。那么这里就会显示remotes/m/master.(m--manifest)
#repo-server/master清单库里的default.xml里面指定的单个git库的revision值
#remotes/repo-server/master是远程分支
[root@SVR6 repo-client1]#
执行完repo forall -c git checkout -b master remotes/m/master之后再查看分支时:
[root@SVR6 repo-client1]# repo forall -c git checkout -b master remotes/m/master
... A new repo command ( 1.19) is available.
... You should upgrade soon:
cp /home/Neo/repo/repo-client1/.repo/repo/repo /bin/repo
Branch master set up to track remote branch master from repo-server.
Switched to a new branch 'master'
Branch master set up to track remote branch master from repo-server.
Switched to a new branch 'master'
[root@SVR6 repo-client1]# repo forall -c git branch -a
... A new repo command ( 1.19) is available.
... You should upgrade soon:
cp /home/Neo/repo/repo-client1/.repo/repo/repo /bin/repo
* master
remotes/m/master -> repo-server/master
remotes/repo-server/master
* master
remotes/m/master -> repo-server/master
remotes/repo-server/master
[root@SVR6 repo-client1]#
这样就完成了简单repo服务器的搭建
其中repo forall这个命令的意思是针对repo下所有的git库进行同样的操作
repo forall -c 后接git命令,比如说你要查看所有git库中的代码情况,可以执行repo forall -c git status
如果你要查看提交状态,可以执行repo forall -c git log --stat
[root@SVR6 repo-client1]# repo forall -c git log --stat
... A new repo command ( 1.19) is available.
... You should upgrade soon:
cp /home/Neo/repo/repo-client1/.repo/repo/repo /bin/repo
commit 789317be88ecdc12b53e4c422016494d636b6b32
Author: root
Date: Thu Apr 25 15:52:27 2013 +0800
create project1
0 files changed, 0 insertions(+), 0 deletions(-)
commit 707deec1441ad98aba3fd845f2de79a708eaeb1c
Author: root
Date: Thu Apr 25 15:52:51 2013 +0800
create project2
0 files changed, 0 insertions(+), 0 deletions(-)
[root@SVR6 repo-client1]#
总结:repo其实就是许多Git仓库的总管理员,便于管理和操作的一个python脚本,如果不是很大型的项目,用一个git仓库就好了,如果项目多且大,需要分开管理,那还是使用repo来管理比较好