Last active
May 5, 2021 21:08
-
-
Save fernandrone/b036d970e9a9694feea2c62d6714300d to your computer and use it in GitHub Desktop.
Returns the N biggest git refs
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 | |
# USAGE: gitbig N - returns the N biggest git refs (default N is 10). | |
# | |
# Note that to remove these refs you will need to rewrite the | |
# commit history. See https://confluence.atlassian.com/bitbucket/reduce-repository-size-321848262.html | |
# for more information. | |
if (( `find .git/objects/pack -name *.idx | wc -l` > 1 )); then | |
git gc --aggressive --prune=now | |
fi | |
INDEX=`find .git/objects/pack -name *.idx` | |
echo -e "Searching index `basename $INDEX` for top ${1:-10} biggest files...\n" | |
PACKS=`git verify-pack -v $INDEX | sort -k 3 -nr | head -${1:-10}` | |
FILES=`echo "$PACKS" | awk '{print $1}'` | |
SIZES=`echo "$PACKS" | awk '{print $3}'` | |
ARRSIZES=($SIZES) | |
i=0 | |
for f in $FILES; do | |
FILE=`git rev-list --objects --all | grep $f` | |
echo "`numfmt --to=iec-i --suffix=B --padding=7 ${ARRSIZES[$i]}` $FILE" | |
i=$i+1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To install: