Skip to content

Instantly share code, notes, and snippets.

@emanuelfeld
Last active April 24, 2017 14:26
Show Gist options
  • Save emanuelfeld/efd6488e983de55b83fe0c9233c1a637 to your computer and use it in GitHub Desktop.
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
#!/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
@emanuelfeld
Copy link
Author

fyi, this overwrites .git/info/exclude (but leaves .gitignore untouched)

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