axel
axel

Reputation: 4127

Is there a way to force a message on `git commit` indipendently by prepare-commit-msg?

I've a regex on my prepare-commit-msg git hook that works like a charm!

But when there are some rare occasions where I would like to force specific commit messages, so I would like to overrule this hook.

Is there a way?

I know the flag -n and --no-verify have no effect on this hook? Am I looking for something impossible?

Thanks a lot

Upvotes: 2

Views: 1054

Answers (1)

ElpieKay
ElpieKay

Reputation: 30908

One of the solutions is to pass a configuration parameter to git commit when you want to skip prepare-commit-msg or other hooks that would be invoked by git commit.

In the hook:

#!/bin/bash

if [[ "$(git config --get my.skip)" = yes ]];then
    echo skip prepare-commit-msg
    exit 0
else
    echo prepare-commit-msg
    # do something
fi

In the command,

git -c my.skip=yes commit

Compared with -n or --no-verify, a configuration parameter can diable specific hooks more flexibly. You can pass multiple configuration parameters if necessary.

Upvotes: 3

Related Questions