Re: hot to get file sizes in git log output
- From
Jeff King <peff@peff.net>
- Date
- Oct 20, 2017, 21:43 UTC
- Message-ID
- <20171020214312.3kb3ncz2ks7mfxw4@sigill.intra.peff.net>
- In-Reply-To
- <CA+P7+xpdWJbxtxAggRpYR3eE8qjH6TfbYQS_=20aZM7d2RbC0Q@mail.gmail.com>
On Fri, Oct 20, 2017 at 01:44:36PM -0700, Jacob Keller wrote:
Show 15 quoted lines
> On Fri, Oct 20, 2017 at 11:12 AM, David Lang <david@lang.hm> wrote: > > I'm needing to scan through git history looking for the file sizes (looking > > for when a particular file shrunk drastically) > > > > I'm not seeing an option in git log or git whatchanged that gives me the > > file size, am I overlooking something? > > > > David Lang > > I'm not exactly sure what you mean by size, but if you want to show > how many lines were added and removed by a given commit for each file, > you can use the "--stat" option to produce a diffstat. The "size" of > the files in each commit isn't very meaningful to the commit itself, > but a stat of how much was removed might be more accurate to what > you're looking for.
That's a good suggestion, and hopefully could help David answer his original question.
I took the request to mean "walk through history, and for each file that a commit touches, show its size". Which is a bit harder to do, and I think you need to script a little:
git rev-list HEAD |
git diff-tree --stdin -r |
perl -lne '
# raw diff line, capture filename and post-image sha1
if (/^:\S+ \S+ \S+ (\S+) \S+\t(.*)/) {
print "$1 $commit:$2"
}
# otherwise it is a commit sha1
else {
$commit = $_;
}
' |
git cat-file --batch-check='%(objectsize) %(rest)'That should show the size of each file along with the "commit:path" in which it was introduced.
-Peff