Last active
May 4, 2025 05:32
Git pre-commit hook that rejects commits that are too large
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash -eou pipefail | |
# https://www.backblaze.com/blog/how-many-bytes-are-in-a-megabyte-really/ | |
size_limit=$((2 * 2**20)) # 2mbs | |
# https://git-scm.com/docs/git-rev-list#Documentation/git-rev-list.txt---disk-usage | |
commit_size=$(git rev-list --disk-usage HEAD^..HEAD) | |
test "$commit_size" -lt "$size_limit" || ( | |
echo "Commit size is too large: $commit_size > $size_limit" | |
echo "Force commit using --no-verify" | |
exit 1 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@simonseo Yes, I am guessing that your repo doesn't have more than 2 commits?