GIT post-commit hook无法正常工作

时间:2017-06-20 15:26:27

标签: git githooks

这是钩子:

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

revisioncount=`git log --oneline -n 1 | cut -d ' ' -f 1`
echo "<?php \$_v = md5('$revisioncount');" > "../../revision"
echo $revisioncount

基本上它的作用是将最后一次提交sha1保存到文件中。

如果我确实提交,我会看到以下内容:

$ git commit -a -m "chore: test hook."
7bd2399
[develop 7bd2399] chore: test hook.
 1 files changed, 1 insertions(+), 1 deletions(-)

但文件未更新。如果我手动运行钩子,它确实有效:

/project/.git/hooks/post-commit

并将输出保存到目标文件。这有什么问题?

0 个答案:

没有答案