Re: hot to get file sizes in git log output

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 20, 2017 at 01:44:36PM -0700, Jacob Keller wrote:

> On Fri, Oct 20, 2017 at 11:12 AM, David Lang <david@xxxxxxx> 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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux