Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git - Cost of each commit

Tags:

git

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?

like image 708
darkfeline Avatar asked May 26 '26 07:05

darkfeline


1 Answers

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!)

like image 197
David J. Avatar answered May 30 '26 03:05

David J.