git钩子 hook post-receive

以下为服务端的配置

在服务器/www/wwwroot/hook.com上新建两个文件夹

public 代码部署

git 裸仓库

git钩子 hook post-receive_第1张图片

切换到git目录下

git钩子 hook post-receive_第2张图片

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

git钩子 hook post-receive_第3张图片

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

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

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

DIR=/www/wwwroot/hook.com/public

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

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

修改post-receive 文件的权限

chmod -R 777 post-receive

以下是本地配置

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

// 初始化一个git仓库
git init
// 添加远程链接 把192.168.1.1 换成你真实服务器的ip
git remote add origin [email protected]:/www/wwwroor/hook.com/git/test.git

git钩子 hook post-receive_第4张图片

推送时会提示如下错误

# 然后直接执行如下代码
git push --set-upstream origin master

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

git钩子 hook post-receive_第5张图片

然后去到服务端

git钩子 hook post-receive_第6张图片

服务端直接更新了

你可能感兴趣的:(git,git,hook)