Git预提交挂钩未在Windows上运行 [英] Git pre-commit hook not running on windows

查看:93
本文介绍了Git预提交挂钩未在Windows上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始研究Git挂钩,但似乎无法使其运行.

I'm just starting to look into Git hooks, but I can't seem to get them to run.

我建立了一个本地存储库,因此我的项目文件夹中现在有一个".git"目录.我已经在名为"pre-commit.cmd"的C:/path/to/my/project/.git/hooks目录中添加了一个".cmd"文件.这是此文件的内容:

I set up a local repository, so there is now a '.git' directory in my project folder. I have added a '.cmd' file into the C:/path/to/my/project/.git/hooks directory named 'pre-commit.cmd'. Here is the contents of this file:

echo "HOOK RUNNING"
echo. 2>C:/path/to/my/project/.git/hooks/EmptyFile.txt

这应该回显文本"HOOK RUNNING",并在该目录中创建一个空文本文件.但是,如果我通过IDE(NetBeans)提交更改或使用Git Bash提交,则它们似乎都不会运行我的预提交钩子,因为没有创建文件.

This should echo the text "HOOK RUNNING" and create an empty text file in that directory. However, if I commit changes through my IDE (NetBeans) or use Git Bash to commit, neither of them seem to run my pre-commit hook, as no file is created.

我的理解是,要使钩子运行,您要做的就是添加一个带有钩子名称的可执行文件(就像我所做的那样).我在做错什么吗?

My understanding is that all you have to do to get a hook to run is add an executable with the name of the hook (as I have done). Am I doing something wrong?

注意:这是在Windows 7 PC上.

Note: This is on a Windows 7 PC.

推荐答案

如何命名钩子pre-commit(不带任何扩展名)?

What about naming your hook pre-commit (without any extension) ?

编辑:并在第一行或#!/bin/bash(建议在注释中)添加#!/bin/sh

and add #!/bin/sh on the first line or #!/bin/bash (suggested in comments)

这篇关于Git预提交挂钩未在Windows上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆