在git日志中显示提交大小 [英] Show commit size in git log

查看:206
本文介绍了在git日志中显示提交大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取git log输出中显示的提交大小?

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

您可能将 commit size 理解为它的父母与自己之间的差异,或者任何合理的东西告诉您该提交有多大.

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

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

git log has a --log-size option but its the size of the log message, not the commit itself.

推荐答案

提交的大小"可能意味着不同的含义.如果您是说要占用多少磁盘存储空间,那么用Git讲是很棘手的,而且可能会毫无用处.诸如SVN存储之类的东西会提交为增量,而当您在Git中更改文件时,它会将文件的新副本存储为图形数据库中的对象.一个对象可以在许多提交中共享.虽然这听起来可能效率很低,但是Git有许多巧妙的方法可以有效地震惊地使用磁盘空间.

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.

如果您要更改多少行,那很容易.您可以使用各种标志来获取更改的文件和行数,其中大多数都带有"stat"一词.例如,git log --shortstat会告诉您更改了多少文件,以及插入和删除了多少行.这是一个例子.

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 --shortstat will tell you how many files changed, and how many lines were inserted and deleted. Here's an example.

commit e3d1909c875ea0c1a64246d735affa039ad11aa0 (origin/master, origin/HEAD)
Author: Michael G. Schwern <schwern@pobox.com>
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(+)

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

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.

commit 0f28d9a96bc92d802b57900ce4a06db71cbaef6d
Author: Michael G. Schwern <schwern@pobox.com>
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 100644表示此替换的blob对象(文件)1d539bd为538440f,并使用权限0644.如果运行git cat-file -s 538440f,它将告诉我该对象为4356字节.这就是未压缩的大小.磁盘上只有1849个字节.

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

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

在我git gc之后,甚至目标文件也消失了.现在,所有内容都在使用不到1万的压缩文件中.

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

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

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

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

这篇关于在git日志中显示提交大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆