git使用hooks的post-receive进行自动远程部署
前言
最近做了个博客,因为是纯前端的项目,想着做一个简单的、类似于jenkins自动化部署的东西。
想到了用git的hooks,代码提交到git上会自动把最新代码更新到web目录。以后提交代码就相当于实现了部署工作。
当然,这种方式最好是你的git服务器和你的web服务器在同一台机子上。
进入正题
进入git裸仓库里面可以看到 hooks文件夹
[root@VM-0-12-centos web]# cd fanyicloudBlog.git/
[root@VM-0-12-centos fanyicloudBlog.git]# ll
drwxr-xr-x 2 git git 4096 8月 20 12:01 branches
-rw-r--r-- 1 git git 66 8月 20 12:01 config
-rw-r--r-- 1 git git 73 8月 20 12:01 description
-rw-r--r-- 1 git git 23 8月 20 12:01 HEAD
drwxr-xr-x 2 git git 4096 8月 20 14:26 hooks
-rw-r--r-- 1 root root 5936 9月 9 09:19 index
drwxr-xr-x 2 git git 4096 8月 20 12:01 info
drwxr-xr-x 168 git git 4096 9月 9 09:19 objects
drwxr-xr-x 4 git git 4096 8月 20 12:01 refs
进入hooks文件夹,创建post-receive文件并编辑下面内容
git --work-tree=/home/web/fanyicloud --git-dir=/home/web/fanyicloudBlog.git checkout -f
其中,--work-tree= 对应的是你web目录地址,--git-dir= 对应的是你Git仓库地址。
这样就完成了,试着提交一次代码,你会惊奇的发现web目录也更新了。
版权声明:
作者:白纸画
链接:https://www.fanyicloud.cn/article-15.fan
来源:白纸画的博客
文章版权归作者所有,未经允许请勿转载。

全部评论