Created
February 23, 2016 02:09
-
-
Save eyedeekay/2bf919547b4161e27efe to your computer and use it in GitHub Desktop.
Remove large files from git history automatically
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
#! /bin/sh | |
#This scipt searches for files larger than 100mb under the working directory and removes | |
#them from git automatically using git filter-branch. This makes it kind of dangerous, | |
#but also automatic and pretty useful. | |
WORKING_DIR=$(pwd) | |
for file in $(find "$WORKING_DIR" -size +100000000c -ls | grep -v ".git"); do | |
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $file" HEAD | |
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment