How big is a Git commit? - ratfactor
The size of a Git commit varies depending on several factors. First, Git stores objects as zlib-compressed data, so the exact size of a commit depends on the compressibility of the files involved. The more repetitive the data, the better the compression.
Additionally, Git converts object files into more efficient packfiles, which saves space by eliminating redundancy across objects. To demonstrate this, the author conducted experiments with loose objects and different scenarios:
1. Committing 3 bytes of change to a file in a directory of 50 files resulted in a 17,145-byte commit.
2. Committing 3 bytes of change to a single-file repo generated an 8,709-byte commit.
3. Committing a 583,840-byte binary file produced a 297,873-byte commit.
4. Committing a 16,415,223-byte source file resulted in a 1,622,188-byte commit.
These examples show that kilobytes of overhead exist even for tiny commits, with the exact amount depending on the size of the file or directory tree involved. For larger commits with a small number of files, the stored data in the .git directory is typically 50% to 10% of the uncompressed committed files, making Git extremely efficient.
The author also explored the compressed sizes of various file types, noting that binary files compress quite a bit, while text files have impressive compression as well. In summary, the size of a Git commit is highly dependent on the compressibility of the files and the efficiency gained through the use of packfiles.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.