php - git post-receive 钩子(Hook)在 php 中

标签 php git githooks

我希望能够在 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/

相关文章:

git - 如何在git pre-push hook中获取远程分支名称

php - Mysql PHP,检索字符串包含撇号无法替换

php - 无法将图像上传到应用程序 Codeigniter 外部的文件夹

php - 延迟函数 PHP

ruby-on-rails - 是否有一个 gem 可以让 Git 和 Rails 协同工作以实现更强大的迁移?

git - 为裸 repo 设置接收后 Hook

git - 在 git pre-commit hook 中临时修改工作目录和暂存区

PHP 在 MYSQL 数据库和日期方面需要帮助

git - 如何在git repo中grep文件?

c# - Git 提交并推送二进制文件,但不保留历史记录