Git钩子(pre-commit等)无法自动执行问题求助
Git钩子脚本无法自动执行排查求助
我的Git钩子脚本(pre-commit、post-commit、pre-receive、pre-push等)均无法自动执行。此问题并非重复提问,我已尝试过同类问题的常规解决方案,但均无效。
已尝试的操作
- 执行
chmod +x为钩子脚本赋予可执行权限 - 配置钩子路径
- 重命名脚本(移除.sample后缀)
仓库与钩子文件信息
仓库根目录结构:branches config description HEAD hooks info objects refs
hooks目录下的文件列表:
applypatch-msg.sample fsmonitor-watchman.sample post-update.sample pre-commit prepare-commit-msg.sample pre-rebase.sample update.sample commit-msg post-merge.sh pre-applypatch.sample pre-commit.sample pre-push pre-receive
执行情况
手动运行钩子脚本一切正常,例如执行bash pre-commit时,能正常输出交互提示。但执行git commit -m "Test hooks"或git push时,钩子脚本完全不生效。
环境与仓库创建信息
- Git版本:
2.39.1 - 仓库创建环境:安装Ubuntu 18.04.6 LTS的虚拟机
- 仓库创建步骤:
mkdir project1.git cd project1.git git init --bare
- 克隆方式:从本地Windows电脑克隆,命令为
git clone git@{ip}:/home/git/git_repositories/project1.git/
pre-commit脚本内容
#!/bin/sh # # An example hook script to verify what is about to be committed. # Called by "git commit" with no arguments. The hook should # exit with non-zero status after issuing an appropriate message if # it wants to stop the commit. # # To enable this hook, rename this file to "pre-commit". echo "You are about to commit" $(git diff --cached --name-only --diff-filter=ACM) echo "to" $(git branch --show-current) while : ; do read -p "Do you really want to do this? [y/n] " RESPONSE < /dev/tty case "${RESPONSE}" in [Yy]* ) exit 0; break;; [Nn]* ) exit 1;; esac done
内容的提问来源于stack exchange,提问作者kams
相关产品推荐
相关产品推荐

