git 使用钩子直接推送到工作目录

远端机器

$ mkdir /www/teacherapi  # 创建工作目录

$ cd /data/git

$ git init teacherapi.git --bare --shared

Initialized empty shared Git repository in /data/git/teacherapi.git/

$ cd teacherapi.git/

$ vi hooks/post-receive # 或者使用 $ cat > hooks/post-receive 创建并键入如下代码,最后ctrl+d保存退出,

#!/bin/sh

GIT_WORK_TREE=/www/teacherapi git checkout -f <branch>  # 默认master分支

$ chmod +x hooks/post-receive  # 设置可执行权限

 

也可以用下面代码片段

$ cd git

$ mkdir somesite.git

$ cd somesite.git/

$ git init --bare

Initialized empty Git repository in /home/caius/git/somesite.git/

$ git --bare update-server-info

$ git config core.worktree /home/caius/vhosts/somesite.com/htdocs

$ git config core.bare false

$ git config receive.denycurrentbranch ignore

$ cat > hooks/post-receive

#!/bin/sh

git checkout -f

^D

$ chmod +x hooks/post-receive

 

工作树更新完成后执行脚本

$ cd /gitpah/hooks/

$ vi post-checkout  #创建post-checkout键入如下代码,当'git-checkout'命令更新完整个工作树(worktree)后,这个钩子就会被调用

#!/bin/sh

/etc/init.d/teacherapitest.tbkt.cn restart

$ chmod +x post-checkout

 

本地机器

$ git clone ssh://root@192.168.0.106:6022/data/git/teacherapi.git

$ cd teacherapi/

$ echo 'Hello, world!' > index.html

$ git add index.html

$ git commit -m "init project"

$ git push origin master:master

 

添加远程仓库

$ git remote add 106 ssh://root@192.168.0.106:6022/opt/gitdata/chsy_cms.git

 

远程推送过程中报错:cannot run hooks/post-receive: No such file or directory

除了检查post-receive文件内容外,还要看看文件格式对不对,使用$ cat -A hook/post-receive 查看

 

文档内容参考:

http://caiustheory.com/automatically-deploying-website-from-remote-git-repository

http://toroid.org/ams/git-website-howto

更多钩子用法:http://www.360doc.com/content/12/1012/11/10140166_241004726.shtml

转载于:https://www.cnblogs.com/weiok/p/4772772.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值