Gitolite 服务器架设教程
文章目录
适用环境
- ubuntu 16.04
- git版本管理
- gitolite企业轻量级版本管理
- 没有代码提交审核机制
- IP: 192.168.1.132
安装 gitolite
- 安装 gitolite
$ aptitude search gitolite
- 创建专用账户 git
$ sudo adduser git
- 把管理员公钥准备就绪
$ cp Tony132_admin.pub /tmp/Tony132_admin.pub
- 创建目录
$ sudo mkdir -p /usr/share/gitolite/conf /usr/share/gitolite/hooks
- 下载gitolite源代码
$ git clone git://github.com/ossxp-com/gitolite.git
- 执行安装
$ cd gitolite/src
$ sudo ./gl-system-install /usr/local/bin/ /usr/share/gitolite/conf /usr/share/gitolite/hooks
- 切换专用git账户执行安装脚本
sudo su git
gl-setup /tmp/Tony132_admin.pub
- 使用管理员账户克隆gitolite-admin库
su tony
git clone git@192.168.1.132:gitolite-admin.git
版本库基本操作
基于testing.git进行操作
下载远程版本
初始上传,需要管理员上传默认创建master分支,然后就可以进行 push / pull 操作
$ git clone git@192.168.1.132:testing.git
$ git config --global push.default simple
选择这个配置
$ git push
Counting objects: 3, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 233 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: *** hooks.mailinglist is not set so no email will be sent
remote: *** for refs/heads/master update 0000000000000000000000000000000000000000->9d125e498915bcbdf5f2bf00ff6f1810660d3722
To git@192.168.1.132:testing.git
* [new branch] master -> master
~/linux/testing$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@192.168.1.132:testing.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
上传修改
git add file.name
git push
git pull
本地创建远程分支提交
创建远程分支,同样需要管理员身份创建,普通用户没有权限
git checkout -b develop
$ git push origin develop
Counting objects: 2, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 229 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: *** hooks.mailinglist is not set so no email will be sent
remote: *** for refs/heads/develop update 0000000000000000000000000000000000000000->4518518abe9a4e5898a564dc1d86c012c4b4c13e
To git@192.168.1.132:testing.git
* [new branch] develop -> develop
然后执行
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> develop
git branch --set-upstream-to=origin/develop develop
查看配置文件如下所示
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@192.168.10.132:testing.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "develop"]
remote = origin
merge = refs/heads/develop
Git服务器版本管理应用实例
新建一个版本库上传到服务器
以管理员身份增加 conf/gitolite.conf
$ vim conf/gitolite.conf
+repo ai-base
+ RW+ = @admin
+ RW = @developer
+
在本地提交修改后 ,上传
gitolite-admin$ git push
Counting objects: 4, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 435 bytes | 0 bytes/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: *** hooks.mailinglist is not set so no email will be sent
remote: *** for refs/heads/master update 23e01eb692615e898ba761b2d154285c29d25a60->f5f3db17a2e43ed883bce8be263098526c0dfee7
remote: Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/'(sub { <-- HERE .*})'/ at /usr/local/bin/gl-compile-conf line 523.
remote: creating ai-base...
remote: Initialized empty Git repository in /home/git/repositories/ai-base.git/
To git@192.168.10.132:gitolite-admin.git
23e01eb..f5f3db1 master -> master
remote: creating ai-base…
remote: Initialized empty Git repository in /home/git/repositories/ai-base.git/ 这个地方就是自动在提交的时候创建一个空的版本库
查看远程版本库的生成情况
$ ssh git@192.168.10.132
PTY allocation request failed on channel 0
hello alex, this is gitolite v1.5.4-452-g96775cf running on git 2.7.4
the gitolite config gives you the following access:
@R_ gitolite-admin
R W ai-base
@R_ @W_ testing
@C R W users/alex/[a-zA-Z].*
alex创建私人版本库 /users/alex/xxx.git
以普通用户的身份创建属于用户本身的版本库
$ mkdir track
$ cd track/
$ git init
$ git commit --allow-empty
$ git remote add origin git@192.168.10.132:users/alex/track.git
$ git push origin master
Initialized empty Git repository in /home/git/repositories/users/alex/track.git/
Counting objects: 2, done.
Writing objects: 100% (2/2), 160 bytes | 0 bytes/s, done.
Total 2 (delta 0), reused 0 (delta 0)
remote: *** hooks.mailinglist is not set so no email will be sent
remote: *** for refs/heads/master update 0000000000000000000000000000000000000000->deb7edc7ae01d236e7e33ed16df82abdb53e16d8
To git@192.168.10.132:users/alex/track.git
* [new branch] master -> master
迁移SVN到GIT
安装 git-svn
$ sudo aptitude install git-svn
使用svn创建一个本地版本库
- 创建一个svn的版本库
$ sudo mkdir -p /path/to/svn/repos/demo
$ svnadmin create /path/to/svn/repos/demo
- 下载版本库
$ svn co file:///path/to/svn/repos/demo svndemo
- 创建主干,里程碑和分支
$ cd svndemo/
$ mkdir trunk tags branches
$ svn add *
$ sudo svn ci -m "initialized."
$ svn log
- 增加内容提交
$ echo hello > trunk/README
$ svn add trunk/README
$ sudo svn ci -m "hello"
$ svn up
- 创建分支和里程碑
$ svn cp trunk branches/demo-1.0
$ sudo svn ci -m "new branch: demo-1.0"
$ sudo svn cp -m "new tag: v1.0" trunk file:///path/to/svn/repos/demo/tags/v1.0
git-svn 下载 svn库
1 使用git下载svn版本库
$ git svn clone -s file:///path/to/svn/repos/demo git-svn-demo
Initialized empty Git repository in /home/tony/linux/git_test/git-svn-demo/.git/
r1 = 9a7482685476790c32c32ae61b20006a03bdce80 (refs/remotes/origin/trunk)
A README
r2 = e1fd65728b801cb72ed4d76805bb01372651ed55 (refs/remotes/origin/trunk)
Found possible branch point: file:///path/to/svn/repos/demo/trunk => file:///path/to/svn/repos/demo/branches/demo-1.0, 2
Found branch parent: (refs/remotes/origin/demo-1.0) e1fd65728b801cb72ed4d76805bb01372651ed55
Following parent with do_switch
Successfully followed parent
r3 = 5d546cefc53cabcda7f692317208a9cf5810c8cd (refs/remotes/origin/demo-1.0)
Found possible branch point: file:///path/to/svn/repos/demo/trunk => file:///path/to/svn/repos/demo/tags/v1.0, 2
Found branch parent: (refs/remotes/origin/tags/v1.0) e1fd65728b801cb72ed4d76805bb01372651ed55
Following parent with do_switch
Successfully followed parent
r4 = 2194c2521040ddbe1caa45d31f0c73ae60983eb8 (refs/remotes/origin/tags/v1.0)
Checked out HEAD:
file:///path/to/svn/repos/demo/trunk r2
2 查看版本库
会发现多了一个 .git/ 目录
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[svn-remote "svn"]
url = file:///path/to/svn/repos/demo
fetch = trunk:refs/remotes/origin/trunk
branches = branches/*:refs/remotes/origin/*
tags = tags/*:refs/remotes/origin/tags/*
3 查看文件及内容
$ cd git-svn-demo/
$ ls
README
$ $ cat README
hello
4 查看提交日志
$ git log
commit e1fd65728b801cb72ed4d76805bb01372651ed55
Author: root <root@8aff20e5-da2e-4909-ac8e-e0ee3fba95ef>
Date: Mon Oct 21 07:16:22 2019 +0000
hello
git-svn-id: file:///path/to/svn/repos/demo/trunk@2 8aff20e5-da2e-4909-ac8e-e0ee3fba95ef
commit 9a7482685476790c32c32ae61b20006a03bdce80
Author: root <root@8aff20e5-da2e-4909-ac8e-e0ee3fba95ef>
Date: Mon Oct 21 07:14:56 2019 +0000
initialized.
git-svn-id: file:///path/to/svn/repos/demo/trunk@1 8aff20e5-da2e-4909-ac8e-e0ee3fba95ef
5 查看提交分支和里程碑
$ git branch -a
* master
remotes/origin/demo-1.0
remotes/origin/tags/v1.0
remotes/origin/trunk
现开发SVN版本库迁移到GIT
如果之前的svn提交和git没有任何关系,已经开发了两三年了,那就没有办法使用前面的手动迁移了,这里有一个现有的解决方案可以解决这个问题。
git svn clone svn://192.168.1.10/path/to/robot --no-metadata --authors-file=svnusers.txt robot
git svn clone — 是Git的迁移命令
–no-metadata — 去除了svn上很多杂乱的参数信息,保留了清晰简洁的提交记录信息
–authors-file — 版本库提交用户映射文件
robot — 空文件夹,要导入的文件夹路径
$ cat svnusers.txt
root=root<root@email.com>
tony=Tony<tony@email.com>
用户的格式为
“=”前为svn帐号
“=”后为git帐号
尖括号为git用户电子邮箱
如果svn账户未全部列举,执行迁移时会报错,并提示svn账户没有对应的转换信息
基于已有的git版本库创建远程版本库
新建一个本地版本库 markdown
$ mkdir markdown
$ cd markdown
$ git init
$ vim Gitolite服务器架设.md
$ git add -A
$ git commit -m "Gitolite服务器架设.md test.md initialized"
增加内容
$ vim test.md
$ git add test.md
$ git commit -m "git add test.md"
使用gitolite 创建远程一个空库
$ cd gitolite-admin/
$ vim conf/gitolite.conf
4 repo markdown
5 RW+ = @admin
6 R = @all
...此处省略掉一些提交的操作
$ git push
在本地已有的.git上传
1 从服务器下载版本库
$ git clone git@server:markdown.git
2 备份版本库配置信息
$ cd markdown/
$ cp -fv .git/config config
3 把本地的版本库覆盖下载的版本库
$ cp -rfv localdir/markdown/.git/* .git/*
4 恢复配置信息
$ cp config .git/config
5取出版本提交服务器
$ git reset HEAD --hard
$ git push
能看到这里,完成这一步,那么恭喜你,成功了!