Show commit size in git log

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

You can understand the size of the fixation as the difference between his parents and himself, or something reasonable that tells you how big the fixation is.

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

+8
git git-log
source share
1 answer

The β€œsize” of a commit can mean different things. If you mean how much disk storage is required ... it's very hard to say in Git and probably unproductive. While something like SVN repositories makes a delta when you change a file in Git, it saves a new copy of the file as an object in the graph database. One object can be used in many commits. Although this may seem inefficient, Git has many smart ways to make good use of disk space.

If you mean how many lines have changed, this is easy. You can use various flags to find out how many files and lines have been changed, most of them have the word "stat" in them. For example, git log --shortstat will tell you how many files were changed and how many lines were inserted and deleted. Here is 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(+) 

If you need the idea of ​​disk storage that commit represents, you need to get the identifiers of the new files (blob objects) created by the commit, and then check their size. You can see them in 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 indicates that this replaced object (file) 1b540bb is replaced by 538440f and uses the permissions of 0644. If you run git cat-file -s 538440f , it tells me that the object has 4356 bytes. This is an uncompressed size. On disk, it is only 1849 bytes.

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

After i git gc even the object file disappeared. Now everything is in a package using less than 10 thousand.

 $ 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 blobs from commit in a more automated way.

+8
source share

All Articles