semi
semi

Reputation: 622

How can I see how much a directory has added to a git repos total size?

I'm talking to someone about the effects committing vendored code has on a repository has on total git size. I'd like to be able to bring some numbers to the discussion.

While it's easy enough to see the current size of the directory (du -sh vendor/), that isn't really accurate as it does not reflect the previous states of the files that are still in history, nor does it factor in git packing and compression.

Is there a way to get the size contribution of a directory that factors these things in?

Upvotes: 3

Views: 40

Answers (1)

anothernode
anothernode

Reputation: 5397

I just found this script. It seems to work fine and should be helpful here, even though it doesn't do exactly what you are asking for.

#!/bin/bash -e

# work over each commit and append all files in tree to $tempFile
tempFile=$(mktemp)
for commitSHA1 in $(git rev-list --all); do
    git ls-tree -r --long "$commitSHA1" >>"$tempFile"
done

# sort files by SHA1, de-dupe list and finally re-sort by filesize
sort --key 3 "$tempFile" | \
    uniq | \
    sort --key 4 --numeric-sort --reverse

# remove temp file
rm "$tempFile"

Upvotes: 1

Related Questions