以下为服务端的配置
在服务器/www/wwwroot/hook.com上新建两个文件夹
public 代码部署
git 裸仓库

img

切换到git目录下

img

然后进入/www/wwwroot/hook.com/git/test.git/hooks

img

复制一份post-receive.sample 并改名为post-receive

1
[root@iZbp1938t1plpi1gikahmmZ hooks]# cp post-receive.sample post-receive

然后编辑 post-receive 添加如下代码 保存退出

1
2
3
4
5
DIR=/www/wwwroot/hook.com/public

git --work-tree=${DIR} clean -fd

git --work-tree=${DIR} checkout --force

修改post-receive 文件的权限

1
chmod -R 777 post-receive

以下是本地配置
在本地上新建一个文件夹 然后添加为远程仓库

1
2
3
4
// 初始化一个git仓库
git init
// 添加远程链接 把192.168.1.1 换成你真实服务器的ip
git remote add origin root@192.168.1.1:/www/wwwroor/hook.com/git/test.git

img

推送时会提示如下错误

然后直接执行如下代码

1
git push --set-upstream origin master

然后输入你的服务器密码即可

img

然后去到服务端

img

服务端直接更新了