Skip to content

Instantly share code, notes, and snippets.

@lilydjwg
Created December 31, 2017 08:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lilydjwg/bae8e2e496496cdcd184834586ea35a4 to your computer and use it in GitHub Desktop.
Save lilydjwg/bae8e2e496496cdcd184834586ea35a4 to your computer and use it in GitHub Desktop.
git-ls-large: find large objects in your git repo
#!/bin/bash -e
if [[ $# -gt 1 ]]; then
idx=($@)
else
idx=(.git/objects/pack/pack-*.idx)
fi
objects=$(git verify-pack -v "${idx[@]}" | grep -v -e 'non delta' -e 'chain length' -e '.git/objects' | sort -k3nr | head)
echo "All sizes are in kiB's. The pack column is the size of the object, compressed, inside the pack file."
output="size,pack,SHA,location"
while read -r line; do
# extract the size in bytes
size=$(($(awk -F' ' '{print $3}' <<< "${line}")/1024))
# extract the compressed size in bytes
compressedSize=$(($(awk -F' ' '{print $4}' <<< "${line}")/1024))
# extract the SHA
sha=$(awk -F' ' '{print $1}' <<< "${line}")
# find the objects location in the repository tree
other=$(git rev-list --all --objects | grep "$sha")
output="${output}\n${size},${compressedSize},${other}"
done <<< "${objects}"
echo -e "$output" | column -t -s ', '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment