我希望能够在 post-receive Hook 上执行一个 php Hook ,将文件从 git repo 复制到同一服务器上的 web 文件夹,并且只有在它被推送到 master 分支而忽略其他分支时才运行。以下是我目前所掌握的内容。
!/usr/bin/php
<?php
exec("git archive master | tar -x -C /var/www/", $output);
?>
基本上,我不确定如何使用 php 访问 git 参数。
最佳答案
不要忘记接收后 Hook doesn't take arguments :它读取标准输入上的数据。
The "post-receive" script is run after receive-pack has accepted a pack and the repository has been updated. It is passed arguments in through stdin in the form:
<oldrev> <newrev> <refname>
因此您需要阅读 extract the branch 的所述参数(示例在 bash 中,但您可以对其进行调整)
关于php - git post-receive 钩子(Hook)在 php 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8981152/