Introducing 'Git Size' (Command and Visualization)
Paul Hammant shares two commands for Git to help manage space on your hard drive.
Join the DZone community and get the full member experience.
Join For Freei’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 code 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 that the stuff to the right of the # will not be sent to the github web-server hosting the files. the stuff to the right of the # is a 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.
Published at DZone with permission of Paul Hammant, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments