Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Introducing 'Git Size' (Command and Visualization)

DZone's Guide to

Introducing 'Git Size' (Command and Visualization)

Paul Hammant shares two commands for Git to help manage space on your hard drive.

· DevOps Zone ·
Free Resource

Can you release faster without sacrificing quality? See how with our free ebook Strategies for a Successful Test Automation Project and a free trial of Ranorex Studio today!

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 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):

https://paul-hammant.github.io/git-size/total.html#ImpiZWhhdmUvamJlaGF2ZS1jb3JlIiwzMTMyMCwx MTkyNCw4MzQ0LDUxNTg4CiJqYmVoYXZlL2piZWhhdmUtdHV0b3JpYWwiLDcyOCwyMjAsMCw5NDgKImpiZWhhdmUvamJl aGF2ZS13ZWIiLDE3NzIsMTM5Niw5MjAsNDA4OAoibWF2ZW4taHBpLXBsdWdpbiIsMTc4NCw2MjAsMTMyOCwzNzMyCiJ4 dW5pdC1wbHVnaW4iLDE0MTYsMzU4OCwxNDkyOCwxOTkzMgo=

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 xargscan 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.

Get your test automation project off to the right start. Download your free test planning template and a 30-day no-obligation trial of Ranorex Studio today!

Topics:
git ,bash

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}