Chinaunix首页 | 论坛 | 博客
  • 博客访问: 215901
  • 博文数量: 145
  • 博客积分: 3000
  • 博客等级: 中校
  • 技术积分: 1720
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-14 18:42
文章分类

全部博文(145)

文章存档

2011年(1)

2009年(144)

我的朋友

分类: LINUX

2009-10-21 13:05:28

by tangke 2009-10-21

这里我们就忽略如何安装apache2,git,git-core,curl这些软件的操作了,
因为这些软件在debian上面都可以通过apt-get install 来进行安装.

1.加载模块

需启动apache的dav_fs和dav模組
a2enmod dav_fs
a2enmod dav

2.配置文件

$vim /etc/apache2/sites-available/git.conf
172.16.28.109:80>
        ServerName 172.16.28.109
        DocumentRoot /var/cache/git
       
                DAV On
                Options ExecCGI FollowSymLinks Indexes
                # Deny everyything here
                Deny from all
                AuthType Basic
                AuthName "git repository"
       


       
                Allow from all
                Order allow,deny
               



ln -s /etc/apache2/sites-available/git.conf /etc/apache2/sites-enabled/git.conf

3.建立服务器仓库

$cd /var/cache/git/
$mkdir desktoploongson.git
$cd desktoploongson.git
$git --bare init
$cp hooks/post-update.example hooks/post-update
$edit the exec git-update-server-info to git update-server-info
因为在debian系统上面没有git-update-server-info 命令,只有git update-server-info.

4.建立上传版本

$mkdir /tmp/test -pv
$cd /tmp/test
$git init
$echo "hello world" >> hello.c
$git add hello.c
$git commit -m "init repo"
$git remote add origin /desktoploongson.git
$git push origin master
Fetching remote heads...
  refs/
  refs/tags/
  refs/heads/
updating 'refs/heads/master'
  from 7a1da3c9144025f14a6e693b661d326293e2ccc8
  to   f24b83be5a8d675926305edea0d14974ed3d36e7
    sending 3 objects
    done
Updating remote server info
PUT error: curl result=22, HTTP code=403
出现PUT error: curl result=22, HTTP code=403
只要是因为/var/cache/git/desktoploongson.git目录的权限问题
首先修改chmod 777 /var/cache/git/desktoploongson.git -R

$git push origin master
Fetching remote heads...
  refs/
  refs/tags/
  refs/heads/
updating 'refs/heads/master'
  from f24b83be5a8d675926305edea0d14974ed3d36e7
  to   e15d4aeaeedd2949c0e6e0bfd564a2deed11eaf6
    sending 2 objects
    done
Updating remote server info

这部分操作不应该这么作,push代码到上游版本应该采用ssh认证方式。

5.建立克隆版本

$mkdir /tmp/test2 -pv
$cd /tmp/test2
$git clone /desktoploongson.git
这时候test2下面就有一个desktoploongson目录了。

在另外一个client push了资源之后,这边可以通过
$cd desktoploongson
$git pull

tangke@tangke-laptop:/tmp/test2/desktoploongson$ git pull
got e15d4aeaeedd2949c0e6e0bfd564a2deed11eaf6
walk e15d4aeaeedd2949c0e6e0bfd564a2deed11eaf6
got 3606daf19f8d58897a1a8b0320f9a975e968890b
got f24b83be5a8d675926305edea0d14974ed3d36e7
got 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
walk f24b83be5a8d675926305edea0d14974ed3d36e7
got 3e5905d7bb0096683ab40985ab448b57e23b0c6c
From /desktoploongson
   7a1da3c..e15d4ae  master     -> origin/master
Updating 7a1da3c..e15d4ae
Fast forward
 tangke  |    1 +
 tangke2 |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 tangke
 create mode 100644 tangke2
tangke@tangke-laptop:/tmp/test2/desktoploongson$ ls
hello2.c  hello.c  helloc.  helloworld.c  tangke  tangke2

6.权限管理

这里只要涉及到apache2的权限设置管理.
参考了一些网站上面关于git的push操作,目前的一般做法都是通过ssh来进行验证的。
http和gitweb只是提供用户一个友好的界面而已,内部push还都是要通过ssh来进行验证操作.
而且我发现http和gitweb会发生冲突现象,也就是说两者可能只能用一种,只要在于配置文件方面,我使用的是gitweb这种方式。

我的做法是通过ssh来进行push,通过web来进行pull
.git/config

[remote "web"]
        url =
        fetch = +refs/heads/*:refs/remotes/origin/*
[remote "ssh"]
        url = ssh://tangke@172.16.28.199:/var/cache/git/desktoploongson.git
        fetch = +refs/heads/*:refs/remotes/ssh/*
push 操作:
git push ssh master
pull 操作:
git pull web

参看:
http://blog.chinaunix.net/u3/100996/showart.php?id=2074849
http://blog.chinaunix.net/u3/100996/showart.php?id=2074700










阅读(997) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~