gitbashgithubpost-commitgithooks

Post Commit Hook Not Running


My post commit hook is not running after git. I have verified that the hook does work if I just run it from the terminal. The code in the hook is:

#!/bin/sh
#.git/hooks/post-commit
# An example hook script that is called after a successful
# commit is made.
#
# To enable this hook, rename this file to "post-commit".

perl -pi -e 's/([a-f0-9]+)$/'$( git rev-parse HEAD )/ ../../config/commit.git

I did rename the file to post-commit in ./.git/hooks/ and the permissions are -rwxr-x-r-x so I am not sure why it doesn't work.


Solution

  • Try putting some echo lines before and after the perl line like this:

    echo "post-commit started"
    perl ...........
    echo "post-commit finished"
    

    This way you can confirm if the script is actually running, because when you run

    git commit
    

    you should see

    post-commit started
    post-commit finished
    

    Towards the end of your output.