git远程仓库,同步钩子、回撤等相关操作
一、首先安装一个git管理软件,例如golang开发的gogs挺不错的。
二、配置hooks(post-receive)
1、进入git的仓库配置目录,找到hooks目录进入,添加post-receive文件,编辑如下:
#!/bin/sh
unset GIT_DIR
NowPath=`pwd`
echo "now path is :"$NowPath
DeployPath="/data/src/sscmp/"
WebPath="/data/www-data/sscmp/"
echo "deploy path is :"$DeployPath
cd $DeployPath
echo "cd deploy path"
git fetch origin
git pull
echo "deploy done"
cd $NowPath
echo "pull fine"
# --- Finished
rsync -aH --delete --progress --exclude=".git/" $DeployPath $WebPath >/dev/null
echo "rsync fine"
chmod -R 777 $WebPath
exit 0
……