Created
April 26, 2016 07:39
-
-
Save jjones646/76acf6a71c143f095dfdfa17415f9ffc to your computer and use it in GitHub Desktop.
Shows a sorted list (decreasing by size) of objects in a repository's full commit history.
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/bash | |
# Shows you the largest objects in your repo's entire history. Just call this script after | |
# you cd into the repo you'd like to run it on. | |
# | |
# To save the results to a file, just redirect stderr to /dev/null, and then redirect | |
# stdout to the filename of your choice. Here's an example: | |
# | |
# ./git-big-objects.sh 2>/dev/null > sorted-git-objects.txt | |
declare -a on_exit_items | |
function abort_all() | |
{ | |
# Get our process group id | |
PGID=$(ps -o pgid= $$ | grep -o [0-9]*) | |
# Kill it in a new new process group | |
setsid kill -- -$PGID &>/dev/null | |
on_exit 1 | |
} | |
function on_exit() | |
{ | |
# kill any child processes that we started | |
for i in "${on_exit_items[@]}"; do | |
eval $i &>/dev/null | |
done | |
exit $1 | |
} | |
function add_on_exit() | |
{ | |
local n=${#on_exit_items[*]} | |
on_exit_items[$n]="$*" | |
} | |
trap abort_all SIGINT EXIT | |
# create some temporary files and mark them for deletion in the trap callbacks | |
ALL_SHAS="$(mktemp)" | |
add_on_exit rm -rf ${ALL_SHAS} | |
BIG_OBJS="$(mktemp)" | |
add_on_exit rm -rf ${BIG_OBJS} | |
(>&2 echo "creating list of repository objects") | |
git rev-list --objects --all | sort -k 2 2> /dev/null > "${ALL_SHAS}" & | |
git gc &> /dev/null && git verify-pack -v .git/objects/pack/pack-*.idx | egrep "^\w+ blob\W+[0-9]+ [0-9]+ [0-9]+$" | sort -k 3 -n -r 2> /dev/null > "${BIG_OBJS}" & | |
# wait for the previous 2 command to finish | |
wait | |
# show all objects from biggest to smallest | |
for sha in $(cut -f 1 -d\ < "${BIG_OBJS}"); do | |
echo $(grep ${sha} "${BIG_OBJS}") $(grep ${sha} "${ALL_SHAS}") | awk '{print $1,$3,$7}' | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment