Git Post接收挂钩未激活

  • 本文关键字:激活 Post Git git
  • 更新时间 :
  • 英文 :


我的EC2 Amazon Linux开发服务器上有一个git repo。我使用SSH在笔记本电脑上从本地git repo推送更改。

我已经确认推送工作正常,因为我的本地repo的内容在Dev服务器上镜像。然而,我的后接钩似乎没有开火。因为代码没有被签出到我的html目录中。

我甚至尝试过放一个echo命令来至少确认钩子正在发射,但命令行中除了在本地端推送的结果之外没有任何反馈。

#!/bin/sh
#
# An example hook script for the "post-receive" event.
#
# 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>
# For example:
#  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b7$
#
# see contrib/hooks/ for a sample, or uncomment the next line and
# rename the file to "post-receive".
#. /usr/share/git-core/contrib/hooks/post-receive-email
GIT_WORK_TREE=/var/www/html sudo git checkout -f

sudo可能没有保留GIT_WORK_TREE环境变量-它通常被配置为为为运行的命令提供一个净化的环境,尤其是当它们作为root运行时。git有一些命令行参数(特别是--git-dir--work-tree),它们实现了环境变量所要实现的功能。在这种情况下,您可能需要使用这些参数。

我不知道这是否能帮助您解决云服务器问题,但我不得不手动编辑/etc/fstab文件。我的/srv/git文件夹被符号链接到一个硬盘驱动器,该硬盘驱动器是通过fstab文件使用"noexec,user"命令安装的。将其更改为"默认值"最终解决了我的问题。我花了8个小时才弄明白。你也可以试试

$cd /path/to/.git/hooks
$sudo chown git:git post-receive

用于接收后文件。

试试这个:

  1. 别忘了带--shared选项的init repo:

    $git init--共享--裸回购/html.git

    $sudo chgrp-R git repo/html.git

    $sudo usermod-a-G git www数据

  2. 将Git用户添加到sudoers(允许www数据用户使用nopass):

    $sudo visudo

    默认值:git!验证

    git ALL=(www数据)NOPASSWD:/usr/bin/git

  3. 我们的单线邮件接收挂钩:

    sudo-u www数据git--git dir=/home/git/repo/html.git/--工作树=/var/www/html checkout-f

最新更新