Paul Hammant's Blog: Introducing 'git size' (command and visualization)
I’m trying to slim things down - it’s easy to fill a 256GB hard drive on a Mac when you like poking around other people’s source on Github. And, perhaps, 100 of your own repos.
I wrote two commands for Git in bash to supplement Git.
Git size
As run on my Mac (after I zapped 50GB of git repos):
The ‘git size’ sub-command: https://github.com/paul-hammant/git-size (~patches~ PRs welome).
Running it
$ git size jbehave/jbehave-core/
jbehave/jbehave-core: git size:
.git folder: 31M
checkout: 11.6M
ignored: 8.1M
total: 50M
Or, recursive and CSV:
$ git size --csv --csv-headers --recursive .
directory_name,dot_git_folder_size,checkout_size,ignored_size,total_size
"jbehave/jbehave-core",31320,11924,8344,51588
"jbehave/jbehave-tutorial",728,220,0,948
"jbehave/jbehave-web",1772,1396,920,4088
"maven-hpi-plugin",1784,620,1328,3732
"xunit-plugin",1416,3588,14928,19932
Installation
How to install that on a Mac with Homebrew (so you can just do ‘git size’ like other git commands): github.com/paul-hammant/homebrew-tap#git-size
Visualizations
The site for visualizations: https://paul-hammant.github.io/git-size/. It is the gh-pages branch of the git-size
repo, of course.
That pic is the example linked to from the homepage, above. The link itself (so you can see):
Yes, that’s a long URL. It’s OK the browser can handle it. Note too, that the stuff to the right of the # will not being sent to the Github web-server hosting the files. The stuff to the right of the # is an base64 encoded form of the CSV above, or course.
Git slim
This might be buggy, but it works for me - a way to reduce the depth of a clone in-situ.
The ‘git slim’ sub-command: https://github.com/paul-hammant/git-slim
$ cd jbehave/jbehave-core
$ git slim
Size of .git folder before: 31M, best case size after: 3.4M (approx).
Installation
How to install that on a Mac (so you can just do ‘git slim’ as any git command): github.com/paul-hammant/homebrew-tap#git-slim
Thoughts after making these
Bash is quite picky generally, but there’s a particular snafu that bogged me down quite a bit:
Unix command xargs
can blow up when using it to calculate the size of a list of files. I had to drop it, and iterate over files adding up KB sizes. There’s a -a
option but it’s not available installed on base OS X.
I could have installed GNU’s xargs
like so brew install findutils
, but it would be gxargs
instead of xargs and though still possible, it would be harder to keep git-size
Linux compatible.
The D3-using sunburst chart really has to stay online - it is too much for a simple bash-script to handle. It is also a fork of something pre-existing, and I had trouble making it into a single page that could switch between the four size types passed in via CSV (the four radio buttons at the top).
Lastly, I really wanted to do a treemap, but nothing in JavaScript/SVG was quite as pretty as the treemap of the fabled Disk Inventory X. So sunburst it was.