美文网首页
git 中 post-receive 执行git pull不生效

git 中 post-receive 执行git pull不生效

作者: lf2196 | 来源:发表于2020-03-31 16:48 被阅读0次

背景

工程中要实现一个需求,客户端git push后代码能够直接部署到服务器的目录中。

实现方式

可以利用git的hooks中的post-receive来实现代码提交后动作,post-receive中配置如下:

#!/bin/sh
cd /www/myproject  #切换到服务器工程目录
git pull     #拉取代码

但是上面代码git pull并没有生效,网上找了下原因,后面发现 git 的钩子在运行的时候会调用 GIT_DIR 这个环境变量,而不是PWD 这个。所以在 git pull 的时候提示 Not a git repository: ‘.’ ,其中 “.” 正是 GIT_DIR 这个环境变量的值。针对这个问题修复了下脚本代码:

#!/bin/sh  
cd /www/myproject/  
unset GIT_DIR   #重要的是这里  
git pull 

然后就生效了。。。。

相关文章

网友评论

      本文标题:git 中 post-receive 执行git pull不生效

      本文链接:https://www.haomeiwen.com/subject/jitguhtx.html