我使用的是一个django webproject的git 。 我有一个在我的服务器上的裸git回购,并从我的本地机器提交我的提交到它。 我也有我的本地计算机上的testing服务器,但我想在服务器上有2个版本的网站。 一个版本作为活动站点(主分支)和一个版本作为testing服务器(开发分支)。 所以我需要2个工作目录。
我想用post-receive hook来
通常我会这样做
$ cat > hooks/post-receive #!/bin/sh GIT_WORK_TREE=/path/www.example.org git checkout -f $ chmod +x hooks/post-receive
但GIT_WORK_TREE似乎不是我猜的正确select? 有没有更好的办法?
我怎样才能定义分支的工作目录?
根据digitalocean的文章而不是GIT_WORK_TREE,你需要一个–work-tree和–git-dir选项的组合:
git --work-tree=/var/www/html --git-dir=/home/demo/proj checkout -f
对于post-receive脚本,它的结构与你所拥有的结构略有不同:
#!/bin/bash while read oldrev newrev ref do if [[ $ref =~ .*/master$ ]]; then git --work-tree=/var/www/html --git-dir=/home/demo/proj checkout -f fi done
build议:
#!/bin/sh echo echo "*** Moving to Live ***" echo cd /path/to/project || exit unset GIT_DIR git pull origin master echo echo "*** Pulling to Live ***" echo /etc/init.d/nginx restart #exec git-update-server-info
从我的服务器拿走,并为我工作的很好。
不要忘记修复path,远程和重启命令。