Sreeram TP
Sreeram TP

Reputation: 11917

Git skip post-commit hook

I have a git post-commit hook in my repo. I want to skip running this hook sometimes.

To skip pre-commit hook, I know I can use the --no-verify flag while commiting like this

git commit -m "message" --no-verify

But this is not skipping post-commit hook.

Is it possible to skip post-commit hook? If so how to do it?

Upvotes: 6

Views: 5215

Answers (2)

It is possible. Here is what I would do for Linux and bash:

#!/bin/bash

# parse the command line of the parent process
# (assuming git only invokes the hook directly; are there any other scenarios possible?)

while IFS= read -r -d $'\0' ARG; do
    if test "$ARG" == '--no-verify'; then
        exit 0
    fi
done < /proc/$PPID/cmdline

# or check for the git config key that suppresses the hook
# configs may be supplied directly before the subcommand temporarily (or set permanently in .git/config)
# so that `git -c custom.ignorePostCommitHookc=<WHATEVER HERE> commit ...` will suppress the hook

if git config --get custom.ignorePostCommitHook > /dev/null; then
    exit 0
fi

# otherwise, still run the hook

echo '+---------+'
echo '| H O O K |'
echo '+---------+'

Upvotes: 7

Chris Maes
Chris Maes

Reputation: 37752

From the documentation:

-n --no-verify This option bypasses the pre-commit and commit-msg hooks. See also githooks[5].

so this flag does not skip the post-commit hook. There doesn't seem to be a simple, clean way to skip this flag. For a one-shot operation; you could just disable the hook and enable it again after your commit:

chmod -x .git/hooks/post-commit # disable hook
git commit ... # create commit without the post-commit hook
chmod +x .git/hooks/post-commit # re-enable hook

Upvotes: 8

Related Questions