Skip to content

Instantly share code, notes, and snippets.

@expelledboy
Last active November 24, 2022 06:48
Show Gist options
  • Save expelledboy/b20da879b1fa5a2a68a25f9568c4e877 to your computer and use it in GitHub Desktop.
Save expelledboy/b20da879b1fa5a2a68a25f9568c4e877 to your computer and use it in GitHub Desktop.
Git pre-commit hook that rejects commits that are too large
#!/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
)
@expelledboy
Copy link
Author

@simonseo Yes, I am guessing that your repo doesn't have more than 2 commits?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment