简体   繁体   English

git - 每次提交的成本

[英]git - Cost of each commit

What is the cost for each commit in git? 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? 例如,如果我一次提交更改A和B而不是为每个提交单独的提交,则使用多少(或更少)空间?

TLDR: I predict, intuitively, without testing, that the difference is minimal for practical use cases. TLDR:我直观地预测,没有测试,实际使用情况的差异很小。 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. 我的思维过程:每个提交都包含一个提交消息,树和blob。 See Git for Computer Scientists for a great walk-through. 请参阅Git for Computer Scientists进行一次精彩的演练。 Think of a blob as a diff for one file. 将blob视为一个文件的差异。 In general, on average, I would not expect a difference between making a change in two blobs instead of one. 一般来说,平均而言,我不希望在两个blob中进行更改而不是一个更改。 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.) (树对象是一个子目录和文件名,它告诉git应用blob的位置 - 差异。提交消息正是你认为的那样。)

So put some guesstimates on it: 所以对它进行一些猜测:

  • the tree object might be 10 to 100 bytes 树对象可能是10到100个字节
  • a commit message might be 10 to 200 bytes 提交消息可能是10到200个字节

By these estimates, doubling up means ~ 20 to 300 more bytes. 根据这些估计,加倍意味着大约20到300个字节。

(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. 每个松散对象在磁盘上占用4K最小值。

A single commit at least consists of a commit object, a tree object and a blob object. 单个提交至少包含提交对象,树对象和blob对象。

If allow empty (no file change), then there is only one commit object, but this is not often used. 如果允许为空(没有文件更改),则只有一个提交对象,但不经常使用。

Therefore, 12K is minimum! 因此,12K是最低的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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