回答这个四年前的问题。
如果你想测试钩子,你需要先在本地环境中测试,我给出了后续的详细命令,post-receive
作为示例:
$ mkdir /tmp/hook_test
$ cd /tmp/hook_test
# set local git repo, where you put hooks in it.
$ git clone --bare https://github.com/git/git.git
# set develop environment which is cloned from the new created repo.
$ git clone git.git repo
# copy and rename the hook you need test to "post-receive"
$ cd git.git/hooks
$ cp ~/post-receive-test post-receive
# suppose the hook script is bash script.
# edit "post-receive" and add "set -x" to second line in it to active debug
$ cd /tmp/hook_test/repo
# emulate a hook trigger, do some changes, "git add" and "git commit" it
$ git push
# Now you should see the script "post-receive" runs automatically with debug details.
您应该可以自由运行git push
,更新仅推送到本地存储库/tmp/hook_test/git.git