First a note :
git
compresses files when it stores them in its .git/
structure, and tries to store similar files using only their diffs ;
in that sense, it is difficult to spot "what commit uses up the most space in my .git/
folder".
If you want to measure how much space the files in a commit take up when checked out :
git ls-tree -r -l <commitid>
will list the files along with their individual sizes
git ls-tree -r -l <commitid> | awk '{ sum += $4 } END { print sum }'
will print the total size of these files.
You can put the above shortcut in a script and see what commits take up more than xx
bytes, the next thing is : can you get rid of said commits ?
You may tell git to delete the end of a branch :
If all 'B's mark 'big commits' :
+-- create a new branch here
v
*--*--*--*--*--*--B--B--B--B <- branchA
\ \
\ \-B--B <- branchB
\
*--*--*--* <- branchC
\
\--B <- branchD
In the above diagram, you can tell git to forget branchA
, branchB
and branchD
(and possibly create a new reference to keep the first "no so big" commits),
but when a commit appears in the middle of a branch :
*--*--B--B--*--* <- branchE
your notion of "delete the two Bs" depends heavily on what is stored in your git
repo and how you can remove these commits from a branch's history.
The general advice is : do not delete commits.