Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git disk usage per branch

Tags:

git

diskspace

Do you know if there is a way to list the space usage of a git repository per branch ? (like df or du would)

By "the space usage" for a branch I mean "the space used by the commits which are not yet shared accross other branches of the repository".

like image 220
Anthony O. Avatar asked Dec 05 '12 11:12

Anthony O.


2 Answers

This doesn’t have a proper answer. If you look at the commits contained only in a specific branch, you would get a list of blobs (basically file versions). Now you would have to check whether these blobs are part of any of the commits in the other branches. After doing that you will have a list of blobs that are only part of your branch.

Now you could sum up the size of these blobs to get a result – but that would probably be very wrong. Git compresses these blobs against each other, so the actual size of a blob depends on what other blobs are in your repo. You could remove 1000 blobs, 10MB each and only free 1kb of disk space.

Usually a big repo size is caused by single big files in the repo (if not, you are probably doing something wrong :). Info on how to find those can be found here: Find files in git repo over x megabytes, that don't exist in HEAD

like image 186
Chronial Avatar answered Sep 17 '22 13:09

Chronial


In git 2.3.1 it supports --disk-usage

# reachable objects
git rev-list --disk-usage --objects --all

https://git-scm.com/docs/git-rev-list#_examples

like image 44
Evan Lin Avatar answered Sep 19 '22 13:09

Evan Lin