赞
踩
服务器端,下文简称:A端;
客户端,下文简称:B端;
(注意:A端和B端,都是同一电脑,因为懒得新建两个虚拟机,如果想区分两台电脑,把以下步骤的A端IP地址(localhost)改成对应的IP,就可以了)
sudo apt-get install git-core openssh-server openssh-client
mkdir ~/gitosis_setup
cd ~/ gitosis_setup
git clone git://eagain.net/gitosis
如果失败 用下面的地址:
git clone https://github.com/res0nat0r/gitosis.git
(ps:不排除以上两个链接都会失败,一样到这下载:https://download.csdn.net/download/u014056414/11438865)
cd gitosis
sudo python setup.py install
如果python setup.py install失败,需要安装python-setuptools: sudo apt-get install python-setuptools
a)生成 pub.key(B端)
ssh-keygen -t rsa
生成在 /home/box/.ssh/id_rsa.pub下面,把id_rsa.pub拷贝到A端的tmp目录下(手动拷贝也可以):
scp ~/.ssh/id_rsa.pub box@localhost:/tmp/
b)执行gitosis-init(A端)
cd /tmp
sudo chmod 777 id_rsa.pub
sudo -H -u box gitosis-init < id_rsa.pub
(ps:这里并没有给git新建一个用户,为什么?因为懒。)
此时,会在/home/box目录下生成一些目录,如果其他用户需要clone gitosis-admin.git的权限,需要执行以下操作:
sudo chmod 755 /home/box/repositories/gitosis-admin.git/hooks/post-update
(ps: /home/box/是主目录,注意修改成自己的)
c) 从A端克隆gitosis-admin.git(B端)
mkdir -p share/gittest/
cd share/gittest/
git clone box@localhost:gitosis-admin.git
cd gitosis-admin/
其中,gitosis.conf是gitosis的配置文件,用于配置用户和权限,keydir/是所有组成员的公钥。
查看gitosis.conf文件,内容如下:
[gitosis]
[group gitosis-admin]
members = box@pcbox
writable = gitosis-admin
apt-get install git-daemon-run
vi /etc/sv/git-daemon/run
可以看到:
#!/bin/sh
exec 2>&1
echo 'git-daemon starting.'
exec chpst -ugitdaemon \
"$(git --exec-path)"/git-daemon --verbose --reuseaddr \
--base-path=/var/lib /var/lib/git
将最后一行修改为:
--export-all --enable=receive-pack --base-path=/home/box/
sudo sv restart git-daemon
mkdir repo_server
cd repo_server
git init --bare manifest.git
git init --bare bootable.git
git init --bare cpp.git
git init --bare device.git
mkdir myrepo
cd myrepo
git clone box@localhost:repo_server/manifest.git
(会要求输入用户box在localhost上的密码)
如果报错:
ERROR:gitosis.serve.main:Repository read access denied
fatal: Could not read from remote repository.
解决办法:重新生成pub.key
a)生成 pub.key(B端)
ssh-keygen -t rsa
生成在 /home/box/.ssh/id_rsa.pub下面,把id_rsa.pub拷贝到A端的tmp目录下(手动拷贝也可以):
scp ~/.ssh/id_rsa.pub box@localhost:/tmp/
b)执行gitosis-init(A端)
cd /tmp
sudo chmod 777 id_rsa.pub
sudo -H -u box gitosis-init < id_rsa.pub
cd manifest
在manifest仓库下创建一个default.xml文件。(以下注意xml文件的书写格式)
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="origin" fetch="git://localhost/repo_server"/>
<default revision="master" remote="origin"/>
<project path="bootable" name="bootable"/>
<project path="cpp" name="cpp"/>
<project path="device" name="device"/>
</manifest>
git add -A
git commit -m “add default.xml”
git push origin master
mkdir repo_client
cd repo_client
git clone box@localhost:repo_server/bootable.git
git clone box@localhost:repo_server/cpp.git
git clone box@localhost:repo_server/device.git
在相应的源码仓库中加入源码文件,提交并上传。
cd bootable
echo “hello Project” > hello.txt
git add -A
git commit -m “add hello.txt”
git push origin master
(其他仓库做类似处理)
在repo脚本中有个REPO_URL,它指向服务器端repo仓库的URL。在这里我们定制自己的Repo仓库。我们可以下载一个repo工具
(https://github.com/android/tools_repo或者https://download.csdn.net/download/u014056414/11438865)
,这里我们下载的是tools_repo-master.zip,解压并改名到服务器段的某个目录
cd repo_server
unzip tools_repo-master.zip
mv tools_repo-master repo
将repo置于版本管理下:
cd repo
git init
git add --all
git commit -m “initial”
网上下载一个repo (https://download.csdn.net/download/u014056414/11438865)
sudo cp repo /usr/bin/repo
sudo chmod a+x /usr/bin/repo
vi /usr/bin/repo
修改
REPO_URL = 'https://gerrit.googlesource.com/git-repo'
REPO_REV = 'stable'
为
REPO_URL =
REPO_REV = 'master'
REPO_URL: repo 所调用库和管理引用仓库;
REPO_REV: 本文设置分支为master,可用命令git branch查看:
mkdir myproject
cd myproject
repo init --repo-url=git://localhost/repo_server/repo --no-repo-verify --repo-branch=master -u git://localhost/repo_server/manifest.git
repo sync
repo start master --all
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。