简体   繁体   中英

pre-commit hook not working in macOS but working in Ubuntu

I have a git pre-commit hook script to validate certain thing during commit.

This in my script .githooks/pre-commit

#!/bin/bash

echo "Here I am!"

This is the file permission文件权限

In ubantu when I am committing anything I am able to view the echoed message, where as when I doing the the same thing in MacOS I am getting this error

fatal: cannot run.githooks/pre-commit: No such file or directory

git config is .git/config

配置文件

line break type is CRLF crlf

Also when I am directly running the file ( in MacOS ) from CLI like this, it is giving me the desired output.

./.githooks/pre-commit

My git version is 2.32.0 (Apple Git-132)

could you please try this and see if it's working for you?

brew link --overwrite git
brew update git

You should have the latest version of git -> 2.35.x

Now go to your local repository, ie the project folder, and then to the .git/hooks directory under your project folder.

You can place your hook files here. Ie for pre-commit, the file name should be pre-commit (without any extension).

This should work whenever you try to commit to that specific repository. The main problem in your case seems to be the directory. The hooks should be in the .git/hooks directory of the project folder.

See the screenshots below.

在此处输入图像描述

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM