企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
# 创建git钩子 #### post-receive 挂钩在整个过程完结以后运行,可以用来更新其他系统服务或者通知用户 * * * * * > 服务器搭建git仓库,本地同步到仓库后,服务器网站目录跟着更新,实现此功能可以借助git的`post-receive`。 1. 这里我们做些准备工作,搭建仓库,`mkdir sample.git;cd sample.git;git init --bare --shared` 本地同步代码 `pull push` 网站目录也要是一个仓库。这些都准备好不一一细讲,要注意权限。 2. 进入sample.git目录。 3. cp hooks/post-receive.sample hooks/post-receive 复制post-receive.sample为post-receive,记得要有git可执行x权限 4. vim hooks/post-receive 编辑post-receive文件。编辑内容 ~~~ #!/bin/sh unset GIT_DIR NowPath=`pwd` DeployPath=/home/wwwroot/sample/ cd $DeployPath git pull origin master cd $NowPath exit 0 ~~~ 看看就明白 就是cd到网站目录仓库然后执行git pull。 post-receive钩子的具体详解去看官方文档这里贴着链接[http://https://git-scm.com/book/zh/v2/%E8%87%AA%E5%AE%9A%E4%B9%89-Git-Git-%E9%92%A9%E5%AD%90](http://https://git-scm.com/book/zh/v2/%E8%87%AA%E5%AE%9A%E4%B9%89-Git-Git-%E9%92%A9%E5%AD%90) 这样就搞定了。so easy!!!