Netkiller Version 手札
DVCS(Distributed Version Control System)
2009-12-12
文档最近一次更新于 Thu Jan 12 15:57:18 UTC 2012
版权 © 2009, 2010, 2011, 2012 Neo Chan
版权声明
转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。
|
|
下面是我多年积累下来的经验总结,整理成文档供大家参考:
git-daemon-run
$ sudo apt-get install git-daemon-run
安装后会创建下面两个用户
$ cat /etc/passwd | grep git gitlog:x:117:65534::/nonexistent:/bin/false gitdaemon:x:118:65534::/nonexistent:/bin/false
Git-daemon-run 包携带的文件
$ dpkg -L git-daemon-run /. /etc /etc/sv /etc/sv/git-daemon /etc/sv/git-daemon/run /etc/sv/git-daemon/log /etc/sv/git-daemon/log/run /usr /usr/share /usr/share/doc /usr/share/doc/git-daemon-run /usr/share/doc/git-daemon-run/changelog.gz /usr/share/doc/git-daemon-run/changelog.Debian.gz /usr/share/doc/git-daemon-run/README.Debian /usr/share/doc/git-daemon-run/copyright
同时创建下面配置文件
$ find /etc/sv/git-daemon/ /etc/sv/git-daemon/ /etc/sv/git-daemon/run /etc/sv/git-daemon/supervise /etc/sv/git-daemon/log /etc/sv/git-daemon/log/run /etc/sv/git-daemon/log/supervise
编辑/etc/sv/git-daemon/run配置
$ sudo vim /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/cache /var/cache/git
git-daemon --verbose --reuseaddr \ --base-path=/var/cache /var/cache/git 改为 git-daemon --verbose --reuseaddr \ --export-all --base-path=/opt/git
提示
* 我加上了一个--export-all 使用该选项后,在git仓库中就不必创建git-daemon-export-ok文件。
/etc/services 文件中加入
# Local services git 9418/tcp # Git Version Control System
确认已经加入
$ grep 9418 /etc/services
启动git-daemon
$ sudo sv stop git-daemon or $ sudo runsv git-daemon runsv git-daemon: fatal: unable to change to directory: file does not exist
扫描git端口,确认git-daemon已经启动
$ nmap localhost Starting Nmap 5.00 ( http://nmap.org ) at 2012-01-31 10:45 CST Warning: Hostname localhost resolves to 2 IPs. Using 127.0.0.1. Interesting ports on localhost (127.0.0.1): Not shown: 989 closed ports PORT STATE SERVICE 21/tcp open ftp 22/tcp open ssh 53/tcp open domain 80/tcp open http 111/tcp open rpcbind 139/tcp open netbios-ssn 445/tcp open microsoft-ds 1723/tcp open pptp 3128/tcp open squid-http 3306/tcp open mysql 9418/tcp open git
Testing
$ sudo mkdir -p /opt/git/example.git $ cd /opt/git/example.git $ git init $ sudo vim example.git/.git/config [receive] denyCurrentBranch = ignore $ sudo chown gitdaemon -R /opt/git/* $ touch git-daemon-export-ok
.git/config 文件应该是下面这样
$ cat example.git/.git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [receive] denyCurrentBranch = ignore
git-clone git://localhost/example.git
neo@deployment:/tmp$ git clone git://localhost/example.git example.git Cloning into example.git... warning: You appear to have cloned an empty repository. neo@deployment:/tmp$ cd example.git/ neo@deployment:/tmp/example.git$ echo helloworld > hello.txt neo@deployment:/tmp/example.git$ git add hello.txt neo@deployment:/tmp/example.git$ git commit -m 'Initial commit' [master (root-commit) 65a0f83] Initial commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 hello.txt
我们添加了一些文件,然后再git clone,可以看到文件数目
$ git-clone git://localhost/example.git Initialized empty Git repository in /tmp/example/.git/ remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0)