Skip to content

Instantly share code, notes, and snippets.

@fernandrone
Last active May 5, 2021 21:08
Show Gist options
  • Save fernandrone/b036d970e9a9694feea2c62d6714300d to your computer and use it in GitHub Desktop.
Save fernandrone/b036d970e9a9694feea2c62d6714300d to your computer and use it in GitHub Desktop.
Returns the N biggest git refs
#!/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
@fernandrone
Copy link
Author

To install:

wget -O ~/gitbig https://gist.githubusercontent.com/fernandrone/b036d970e9a9694feea2c62d6714300d/raw/d94453417cfcf0d4993988189a97ebc40d5338e0/gitbig.sh
chmod +x ~/gitbig
sudo mv ~/gitbig /usr/local/bin/gitbig

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