学以致用

focus on Python , C++, and some interest in Go and R

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

访问Git时使用Git协议是最高效的,虽然也存在一些缺陷,主要是没有访问权限的控制,但在可信环境下对速度和效率有较高要求时直接采用git协议还是可以考虑的
在采用Git协议搭建Public Repository时需要注意的事项有:
(1)安装git-daemon,并确保git-daemon所使用的端口(9418)允许accept,这个可以在iptables中配置
(2)创建一个bare repository,可以通过clone来实现,例如$ git clone --bare ~/proj proj.git
(3)在repository中创建git-daemon-export-ok文件,以允许git-daemon将该repository纳入管理,执行

  $ touch proj.git/git-daemon-export-ok
(4)增加访问控制功能,准确地说就是控制read/write
  可以通过$ git config daemon.receivepack true 增加写的权限,否则该repository在使用git协议时只允许读不允许写
  或者在启动git-daemon时显式指定允许receivepack,比如git-daemon --verbose --reuseaddr --base-path=/home/foo --enable=receive-pack

注意,在搭建使用http/https访问git的系统时相对于使用git协议的来说有一些特殊工作要做:
  repository创建完成之后需要执行
update-server-info命令,以便于client找到该git repository所在的server所拥有的references and packs,这些references and packs存放于 $GIT_DIR/info and $GIT_OBJECT_DIRECTORY/info目录下
  所以,方便一点儿的做法是:
  (1)创建public repository之后直接执行如下命令
    $ git --bare update-server-info
  (2)更改post-update hook,利用git的hook在repository更新之后自动执行update-server-info
        将hooks目录下的post-update.sample更改为post-update
    为post-update增加执行权限,$ chmod a+x hooks/post-update

 

参考资料:
(1)http://stackoverflow.com/questions/2085402/what-does-git-update-server-info-do
(2)http://book.git-scm.com/4_setting_up_a_public_repository.html
(3)http://www.elpauer.org/?p=337



posted on 2011-11-11 09:04  Jerry.Kwan  阅读(665)  评论(0编辑  收藏  举报