首页 > 其他 > 详细

Git Hook 同步服务器代码

时间:2015-10-07 21:30:58      阅读:285      评论:0      收藏:0      [点我收藏+]

参考并转载自:

http://www.embbnux.com/2014/09/05/git_server_let_code_auto_deploy/

http://www.chenyudong.com/archives/git-sync-manage-website.html#i

1. 创建远程仓库

$ mkdir /home/www.cnblogs.com/www.cnblogs.com.git #将来网站git的记录存放位置
$ chown -R git:git www.cnblogs.com.git #改权限
$ cd www.cnblogs.com.git
$ git init --bare
Initialized empty Git repository in /home/www.cnblogs.com/www.cnblogs.com.git/

2. 在git远端仓库的hooks目录下新建post-receive文件:

#!/bin/sh
 
#author: embbnux
#Blog of Embbnux: http://www.embbnux.com
 
#判断是不是远端仓库
IS_BARE=$(git rev-parse --is-bare-repository)
if [ -z "$IS_BARE" ]; then
echo >&2 "fatal: post-receive: IS_NOT_BARE"
exit 1
fi
 
unset GIT_DIR
DeployPath="/var/web"
 
echo "==============================================="
cd $DeployPath
echo "deploying the test web"
 
git fetch --all
git reset --hard origin/master
 
time=`date`
echo "web server pull at webserver at time: $time."
echo "================================================"

  保存后赋予可执行权限:

chmod +x hooks/post-receive

  

Git Hook 同步服务器代码

原文:http://www.cnblogs.com/chemandy/p/4859533.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!