Forked from btsai/gist:f0a462ceec17126a5beda5705d323057
Created
April 25, 2017 18:50
-
-
Save vinyar/d214d8300318f582a371d423bc1b8cd4 to your computer and use it in GitHub Desktop.
Ruby script to parse for large files in git repo
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
# gist to create file size list: | |
# run this in irb in your git folder. | |
# will output a text file to the parent folder with a listing of each filepath and file size. | |
# NOTE: nil is added to the end of each line to prevent outputting the result of the iterator blocks. | |
lines = `git gc && git verify-pack -v .git/objects/pack/pack-*.idx`.split("\n"); nil | |
objects = lines.find_all{ |line| line.match(/^\w+ blob\W+[0-9]+ [0-9]+ [0-9]+$/) }; nil | |
shas = `git rev-list --objects --all | sort -k 2`.chomp.split("\n"); nil | |
map = shas.inject({}){ |hash, line| sha, file = line.split(' '); hash[sha] = file unless file.nil?; hash }; nil | |
sizes = objects.map{ |line| sha, type, size = line.gsub(/\s+/, ' ').split(' '); file = map[sha]; [size.to_i, file] if file }; nil | |
sizes = sizes.compact.sort.reverse.map{ |size, file| "#{size}: #{file}" }; nil | |
folder_name = `pwd`.chomp.split('/').last | |
File.open("../file_sizes_#{folder_name}.txt", 'w'){ |f| f.write(sizes.join("\n")) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://naleid.com/blog/2012/01/17/finding-and-purging-big-files-from-git-history