Last active
April 24, 2017 14:26
-
-
Save emanuelfeld/efd6488e983de55b83fe0c9233c1a637 to your computer and use it in GitHub Desktop.
as pre-commit script, automatically add files larger than some size to your repository's .git/info/exclude file
This file contains 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
#!/bin/bash | |
# set max file size to include (in MB) | |
max_size_mb=100 | |
max_size_b="$(($max_size_mb * 1000000))c" | |
git_dir="$(git rev-parse --show-toplevel)" | |
git_exclude=$git_dir/.git/info/exclude | |
files="$(find $git_dir -path $git_dir/.git -prune -o -type f -size +$max_size_b -print | sed "s%$git_dir/%%g" | sed "s/\ /\\\ /g")" | |
echo "$files" > $git_exclude | |
git rm --cached --quiet --ignore-unmatch $files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fyi, this overwrites .git/info/exclude (but leaves .gitignore untouched)