无法访问 git 预接收挂钩的参数

Having trouble accessing the arguments to the git pre-receive hook

我是 运行ning vanilla git(git 版本 2.23.3)作为 AWS 实例上裸存储库的原始主机。

我创建了一个包含以下内容的文件 repo_dir/hooks/pre-receive:

#!/bin/bash -p

echo  > pre-receive-old-hash.txt
echo  > pre-receive-new-hash.txt
echo  > pre-receive-ref.txt

exit 1

我从我的遥控器上进行了一次测试推送。我可以确认挂钩是 运行,因为我收到推送拒绝。

然而,虽然预接收-x.txt 文件存在,但它们是空的。我做错了什么?

https://git-scm.com/docs/githooks#pre-receive

It takes no arguments, but for each ref to be updated it receives on standard input a line of the format:

<old-value> SP <new-value> SP <ref-name> LF

(强调我的 — phd

将您的脚本设为:

#!/bin/bash -p

while read old new refname; do
    echo $old >> pre-receive-old-hash.txt
    echo $new >> pre-receive-new-hash.txt
    echo $refname >> pre-receive-ref.txt
done

exit 1