更新时间:2023-12-05 10:32:16
git help hooks
包含有关 hooks 的文档.当 Git 即将创建/移动/删除引用时,会调用 update
挂钩.每个要更新的引用调用一次,并给出:
git help hooks
contains documentation about the hooks. The update
hook is invoked when Git is about to create/move/delete a reference. It is called once per reference to be updated, and is given:
如果钩子以非零退出代码退出,git
不会更新引用并且用户会收到错误.
If the hook exits with a non-zero exit code, git
won't update the reference and the user will get an error.
因此,为了解决您的特定问题,您可以将以下内容添加到您的 update
挂钩中:
So to address your particular problem, you can add the following to your update
hook:
#!/bin/sh
log() { printf '%s
' "$*"; }
error() { log "ERROR: $*" >&2; }
fatal() { error "$*"; exit 1; }
case $1 in
refs/tags/*)
[ "$3" != 0000000000000000000000000000000000000000 ]
|| fatal "you're not allowed to delete tags"
[ "$2" = 0000000000000000000000000000000000000000 ]
|| fatal "you're not allowed to move tags"
;;
esac