Does Git store a full copy of every file with each commit, or just the changes? How can I tell how much space a commit uses?
How much space does a Git commit actually take up?
Answers
A commit represents a snapshot, but Git does not make a separate full copy of every unchanged file for it. The commit object points to a tree, which describes the files and directories in that snapshot. File contents live in blob objects, and unchanged content can be reused across commits.
The commit object itself holds metadata such as the tree ID, parent commit ID or IDs, author, committer, and message. It is often only a few hundred bytes, though a long message or other metadata can make it larger. New or changed file contents and tree objects can add more storage.
Reply to this answer
For a quick check, run git cat-file -s HEAD. That gives the uncompressed size in bytes of the current commit object, not the size of the files in its snapshot. Run git count-objects -vH for a broader view of storage used by the repository's object database.
There is no single obvious number for the disk space attributable to one commit. Objects can be shared, compressed, or stored together in packfiles, sometimes using deltas against other objects.
Reply to this answer
Watch out for what your disk usage tool is measuring. A small loose object file can occupy more disk space than its actual byte count because the filesystem allocates space in blocks. Once objects are packed together, that loose-file overhead changes too.
Reply to this answer
Add your answer
Answers are reviewed before publication.
7m!corkwinder_582:
So a snapshot describes the whole project, but that does not mean all its contents are duplicated for every commit.