Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pre-commit hook is not running on Windows

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

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 

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?

Note: This is on a Windows 7 PC.

like image 419
user1578653 Avatar asked Dec 16 '13 11:12

user1578653


People also ask

How do I enable pre-commit hook?

Open a terminal window by using option + T in GitKraken Client. Once the terminal windows is open, change directory to . git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file executable.

Can you commit pre-commit hooks?

pre-commit hooks are a mechanism of the version control system git. They let you execute code right before the commit. Confusingly, there is also a Python package called pre-commit which allows you to create and use pre-commit hooks with a way simpler interface.


1 Answers

Name your hook pre-commit (without any file extension).

And add #!/bin/sh on the first line or #!/bin/bash.

like image 95
Asenar Avatar answered Oct 06 '22 12:10

Asenar