简体   繁体   中英

git - Cost of each commit

What is the cost for each commit in git? For example, if I commit changes A and B at once versus making separate commits for each, how much more (or less) space is used?

TLDR: I predict, intuitively, without testing, that the difference is minimal for practical use cases. If you are doing thousands of commits per day, perhaps you should be more analytical about this.

My Thought Process: Each commit consists of a commit-message, tree, and blob. See Git for Computer Scientists for a great walk-through. Think of a blob as a diff for one file. In general, on average, I would not expect a difference between making a change in two blobs instead of one. So what you are left with is one additional tree object and one additional commit message. (A tree object is a subdirectory and filename that tells git where to apply the blob -- the diff. A commit message is just what you think it is.)

So put some guesstimates on it:

  • the tree object might be 10 to 100 bytes
  • a commit message might be 10 to 200 bytes

By these estimates, doubling up means ~ 20 to 300 more bytes.

(Note: this analysis does not factor in disk allocation. So it might be way off base!)

Newly created objects are usually loose objects.

4K minimum is occupied on disk for each loose object.

A single commit at least consists of a commit object, a tree object and a blob object.

If allow empty (no file change), then there is only one commit object, but this is not often used.

Therefore, 12K is minimum!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM