但我们在git提交到远程代码仓库后,要想部署到线上还要到服务器的发布目录下git clone 或者git pull,以前我还自作聪明的写了个脚本,用于自动git pull,登录服务器后直接运行./gitpull.sh就好,后来,直到后来,我发现原来可以有个更简单的方法,那就是hooks,钩子方法,它在你见的代码仓库的hoocks目录下,(/var/opt/gitlab/git-data/repositories/zhangxiaoyuan/66xun.git/hooks)
cd hooks
vi post-receive
#!/bin/sh unset GIT_DIR DeployPath=/mnt/66xun/ #你自己发布网站的目录 git --work-tree=$DeployPath checkout -f publish chmod -R 777 $DeployPath cd $DeployPath git add . -A && git stash git pull origin publish
退出保存
chmod +x post-receive #赋予执行权限
然后在你要发布的地方 git clone 你的git库 /root/HelloWorld --你要发布的网站目录(git clone /var/opt/gitlab/git-data/repositories/zhangxiaoyuan/66xun.git 把/mnt/66xun/66xun里的.git放到/mnt/66xun
)
在本地提交文件,发现文件自动提交到/root/HelloWorld 目录下。成功了
---------------------
作者:KinGofWorLd_v587
来源:优快云
原文:https://blog.youkuaiyun.com/zhy421202048/article/details/52887539
版权声明:本文为博主原创文章,转载请附上博文链接!