# Best way to get number of insertions and deletions from a diff?

2 messages from 2010-10-13 to 2010-10-13. Participants: Pat Notz, Jeff King.
Thread: https://gitlist.dev/t/25439

## Pat Notz, 2010-10-13 19:21

Subject: Best way to get number of insertions and deletions from a diff?
Message-ID: <AANLkTinJuuxOZ2DvCSc2Nb0DAjwmJEyJXeGLHsLkyM1B@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinJuuxOZ2DvCSc2Nb0DAjwmJEyJXeGLHsLkyM1B%40mail.gmail.com

```
I'd like to probe various commits to see how many lines were added or
removed.  For example,

$ git diff --shortstat HEAD HEAD^1
 3 files changed, 5 insertions(+), 5 deletions(-)

That's great but I'd like to do this from a script and parse out those
numbers.  Is there a more plumbing-level way to do this that would be
more robust?  Or, should I just parse this output?

Thanks ~ Pat

```

## Jeff King, 2010-10-13 19:37

Subject: Re: Best way to get number of insertions and deletions from a diff?
Message-ID: <20101013193750.GC13155@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20101013193750.GC13155%40sigill.intra.peff.net
In-Reply-To: <AANLkTinJuuxOZ2DvCSc2Nb0DAjwmJEyJXeGLHsLkyM1B@mail.gmail.com>

```
On Wed, Oct 13, 2010 at 01:21:27PM -0600, Pat Notz wrote:

> I'd like to probe various commits to see how many lines were added or
> removed.  For example,
> 
> $ git diff --shortstat HEAD HEAD^1
>  3 files changed, 5 insertions(+), 5 deletions(-)
> 
> That's great but I'd like to do this from a script and parse out those
> numbers.  Is there a more plumbing-level way to do this that would be
> more robust?  Or, should I just parse this output?

The official plumbing way is --numstat, but you will have to sum the
totals for file yourself. You should also use "git diff-tree" over "git
diff". If you have a lot of commits, the simplest thing is something
like:

  git diff-tree --stdin --numstat <commits

which will automatically check each commit against its parent (though I
think diff-tree will not resolve refs for you, so you may need massage
the input).

-Peff

```
