首页 > 解决方案 > 如何从 pre-push git hook 运行 .exe?

问题描述

所以这是我在谷歌搜索超过 4 小时后得到的结果:

#!C:/Program\ Files/Git/bin/sh.exe echo $SHELL echo "here we go" ./PrePush/GitHook.exe

控制台告诉我:

/usr/bin/bash here we go .git/hooks/pre-push: line 4: ./PrePush/GitHook.exe: No such file or directory

我的 .exe 位于:C:\Users\myUsername\Documents\MyRepos\ProjectName\.git\hooks\PrePush\GitHook.exe 但它可能是我同事驱动器上的任何路径,所以我必须使用本地路径。

我已经尝试过 bin/bash.exe,使用完整路径,使用system(./PrePush/GitHook.exe)(因为我认为它是一个 perl 脚本),但它们都引发了错误。

而且似乎没有“只是”从 git 挂钩调用本地 .exe 的例子。

标签: gitgithooks

解决方案


Git 钩子不会从.git/hooks文件夹中执行。您必须指定可执行文件的正确路径。

"$(git rev-parse --git-dir)/hooks/PrePush/GitHook.exe"

推荐阅读