Skip to content

Instantly share code, notes, and snippets.

@nuclearsandwich
Created September 28, 2012 23:27
Show Gist options
  • Save nuclearsandwich/3802586 to your computer and use it in GitHub Desktop.
Save nuclearsandwich/3802586 to your computer and use it in GitHub Desktop.
Find large files in your git repos
#!/bin/bash
# big_files.bash
## Iterate over commit history and print big files and folders.
## usage: big_files.bash
# git-rev-list - print each revision in the HEAD reference
git rev-list --reverse HEAD \
| while read rev; do
echo "Current revision: $rev"
# git-checkout - Check out a revision locally. Send the warning to /dev/null
git checkout $rev 2>/dev/null
# du - Print the disk usage of a local project
# sort - sort each line descending numerically
# head - take the 10 largest files/folders
du -I ".git" \
| sort -rn \
| head -${nfiles:-"20"}
# Spacer
printf "######################\n\n"
done
# ZOMG We're done!
git checkout master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment