我编写了简单的 shell 脚本来抛出“成功和失败消息”,并将其放在具有所有适当权限的 .git/hooks/下。我想将此脚本称为后期接收。但是脚本不工作,运行脚本只是工作,但作为接收后 Hook 它不起作用。
是他们遗漏了什么还是我错误地理解了接收后 Hook 。有人可以解释客户端和服务器端的钩子(Hook)以及如何执行它们。
我已经搜索过但无法理解。
最佳答案
启用 post-receive
hook 脚本,将文件放在 .git 目录的 hooks 子目录中,该文件同名(没有任何扩展名)并使其可执行:
touch GIT_PATH/hooks/post-receive
chmod u+x GIT_PATH/hooks/post-receive
For more info check this doc: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
例子
检查这个例子(一个简单的部署)
GIT_PATH/hooks/post-receive
:#!/bin/bash
TARGET="/home/webuser/deploy-folder"
GIT_DIR="/home/webuser/www.git"
BRANCH="master"
while read oldrev newrev ref
do
# only checking out the master (or whatever branch you would like to deploy)
if [[ $ref = refs/heads/$BRANCH ]];
then
echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
Source: https://gist.github.com/noelboss/3fe13927025b89757f8fb12e9066f2fa#file-
关于git - 理解 Git Hook - post-receive hook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28106011/