Is it possible to show the total file size difference between two commits? Something like:
$ git file-size-diff 7f3219 bad418 # I wish this worked :)
-1234 bytes
I’ve tried:
$ git diff --patch-with-stat
And that shows the file size difference for each binary file in the diff — but not for text files, and not the total file size difference.
Any ideas?
I made a bash script to compare branches/commits etc by actual file/content size. It can be found at https://github.com/matthiaskrgr/gitdiffbinstat and also detects file renames.
You can pipe the out put of
and compare the 2 numbers.
Expanding on matthiaskrgr's answer, https://github.com/matthiaskrgr/gitdiffbinstat can be used like the other scripts:
Imo it really works well, much faster than anything else posted here. Sample output:
The output directory is funky with ./c/data... as /c is actually the filesytem root.
git cat-file -s
will output the size in bytes of an object in git.git diff-tree
can tell you the differences between one tree and another.Putting this together into a script called
git-file-size-diff
located somewhere on your PATH will give you the ability to callgit file-size-diff <tree-ish> <tree-ish>
. We can try something like the following:In use this looks like the following:
By using
git-rev-parse
it should accept all the usual ways of specifying commit ranges.EDIT: updated to record the cumulative total. Note that bash runs the while read in a subshell, hence the additional curly braces to avoid losing the total when the subshell exits.
EDIT: added support for comparing the index against another tree-ish by using a
--cached
argument to callgit diff-index
instead ofgit diff-tree
. eg:A comment to the script: git-file-size-diff, suggested by patthoyts. The script is very useful, however, I have found two issues:
When someone change permissions on the file, git returns a another type in the case statement:
If a sha-1 value doesn't exist anymore (for some reason), the script crashes. You need to validate the sha before getting the file size:
$(git cat-file -e $D) if [ "$?" = 1 ]; then continue; fi
The complete case statement will then look like this: