在 git log 中显示提交大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40697663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:26:51  来源:igfitidea点击:

Show commit size in git log

gitgit-log

提问by Cyker

How can I get commit size shown in the output of git log?

如何获得在输出中显示的提交大小git log

You may understand commit sizeas the diff between its parents and itself, or anything reasonable that tells you how bigthe commit is.

你可以理解提交大小为告诉你的父母和自己,或任何合理之间的差异有多大提交的。

git loghas a --log-sizeoption but its the size of the log message, not the commit itself.

git log有一个--log-size选项,但它是日志消息的大小,而不是提交本身。

采纳答案by Schwern

The "size" of a commit can mean different things. If you mean how much disk storage it takes up... that's very tricky to tell in Git and probably unproductive. Whereas something like SVN stores commits as deltas, when you change a file in Git it stores a new copy of the file as an object in a graph database. One object can be shared in many commits. While this might sound inefficient, Git has many clever ways to use disk space shockingly efficiently.

提交的“大小”可能意味着不同的东西。如果您的意思是它占用了多少磁盘存储空间……在 Git 中很难说清楚,而且可能效率低下。而像 SVN 这样的东西将提交存储为增量,当您在 Git 中更改文件时,它会将文件的新副本存储为图形数据库中的对象。一个对象可以在多次提交中共享。虽然这听起来效率低下,但 Git 有许多聪明的方法可以惊人地高效地使用磁盘空间。

If you mean how many lines did it change, that's easy. You can use various flags to get how many files and lines changed, most of them have the word "stat" in them. For example, git log --shortstatwill tell you how many files changed, and how many lines were inserted and deleted. Here's an example.

如果你的意思是它改变了多少行,那很容易。您可以使用各种标志来获取更改的文件和行的数量,其中大多数都包含“stat”一词。例如,git log --shortstat会告诉您更改了多少个文件,以及插入和删除了多少行。这是一个例子。

commit e3d1909c875ea0c1a64246d735affa039ad11aa0 (origin/master, origin/HEAD)
Author: Michael G. Schwern <[email protected]>
Date:   Thu Aug 11 13:04:24 2016 -0700

    Add default Travis and AppVeyor configs.

    The AppVeyor one is set up for Dist::Zilla, the hardest of the bunch.

 2 files changed, 60 insertions(+)

If you want an idea of the disk storage that commit represents, you need to get the IDs of the new files (blob objects) the commit created, then check their size. You can see them in a git log -p.

如果您想了解提交所代表的磁盘存储空间,您需要获取提交创建的新文件(blob 对象)的 ID,然后检查它们的大小。您可以在git log -p.

commit 0f28d9a96bc92d802b57900ce4a06db71cbaef6d
Author: Michael G. Schwern <[email protected]>
Date:   Wed Aug 10 09:13:40 2016 -0700

    Remove my name from the gitconfig.

    Now it can be used by anyone. Git will prompt for the user info.

diff --git a/.gitconfig b/.gitconfig
index 1d539bd..538440f 100644
--- a/.gitconfig
+++ b/.gitconfig
@@ -1,18 +1,10 @@
-# If you use this file, remember to change the [user] and [sendemail] sections.
-
...and so on...

index 1d539bd..538440f 100644indicates this replaced blob object (file) 1d539bd with 538440f and uses permissions 0644. If you run git cat-file -s 538440fit tells me the object is 4356 bytes. That's it's uncompressedsize. On disk it's just 1849 bytes.

index 1d539bd..538440f 100644表示此替换 blob 对象(文件)1d539bd 为 538440f 并使用权限 0644。如果您运行git cat-file -s 538440f它,它会告诉我该对象为 4356 字节。那就是未压缩的大小。在磁盘上它只有 1849 字节。

$ ls -l .git/objects/53/8440f84014584432fa5bf09d761926b3d70dbe 
-r--r--r-- 1 schwern staff 1849 Aug 10 09:14 .git/objects/53/8440f84014584432fa5bf09d761926b3d70dbe

After I git gceven the object file is gone. Now everything is in a pack file using less than 10K.

在我git gc什至目标文件消失之后。现在所有内容都在使用小于 10K 的包文件中。

$ tree -h .git/objects/
.git/objects/
├── [ 102]  info
│?? └── [  54]  packs
└── [ 136]  pack
    ├── [1.9K]  pack-d5b7110001ed35cce1aa0a380db762f39505b1c0.idx
    └── [7.8K]  pack-d5b7110001ed35cce1aa0a380db762f39505b1c0.pack

This answershows how to get the blobs from a commit in a more automated fashion.

此答案显示了如何以更自动化的方式从提交中获取 blob。