git 文档中有一个包含解释的完整示例,涵盖了这一点。 链接到示例。
粗略地翻译一下 ruby 示例,我们有:
#!/bin/bash
set -eo pipefail
refname="$0"
oldrev="$1"
newrev="$2"
echo "Enforcing Policies..."
# Iterate over all the commits
for commit in $(git rev-list 538c33..d14fc7); do
git cat-file commit "${commit}" | sed '1,/^$/d' | your-validator
done
Run Code Online (Sandbox Code Playgroud)