# git diff

2 messages from 2011-01-13 to 2011-01-17. Participants: Carter Lamb, Jeff King.
Thread: https://gitlist.dev/t/26274

## Carter Lamb, 2011-01-13 22:46

Subject: git diff
Message-ID: <AANLkTik7cfu_DS=GS5gz_Tu94NC=ZGi-eA8YXztyd9Ra@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTik7cfu_DS%3DGS5gz_Tu94NC%3DZGi-eA8YXztyd9Ra%40mail.gmail.com
In-Reply-To: <AANLkTi=ASvicFGaaDfqxjOxJELWPLKsQwvk7rEeT36Fh@mail.gmail.com>

```
I use git diff --summary --numstat <commit> to report the files
modified, created, and deleted between the current commit and some
prior commit. The --stat and --numstat options count the lines added
and deleted for each file. Is there a way to report the lines modified
for each file. For example:

Given content below for commit 1:
aaaaa
ccccc

Given content below for commit 2:
aaaaa
bbbbb
ccccc

Given content below for commit 3:
Aaaaa
Bbbbb
ccccc
ddddd

git diff --numstat between commits 1 and 2 will report one line added.
git diff --numstat between commits 2 and 3 will report three lines
added and two lines deleted.
I'd like to see the diff between commits 2 and 3 report two lines
modified and one line added.
Can this be done?

Best,
Carter

```

## Jeff King, 2011-01-17 22:30

Subject: Re: git diff
Message-ID: <20110117223021.GA31045@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20110117223021.GA31045%40sigill.intra.peff.net
In-Reply-To: <AANLkTik7cfu_DS=GS5gz_Tu94NC=ZGi-eA8YXztyd9Ra@mail.gmail.com>

```
On Thu, Jan 13, 2011 at 04:46:16PM -0600, Carter Lamb wrote:

> I use git diff --summary --numstat <commit> to report the files
> modified, created, and deleted between the current commit and some
> prior commit. The --stat and --numstat options count the lines added
> and deleted for each file. Is there a way to report the lines modified
> for each file. For example:

Not really, because it's not well defined. Consider your example:

> Given content below for commit 1:
> aaaaa
> ccccc
> 
> Given content below for commit 2:
> aaaaa
> bbbbb
> ccccc
> 
> Given content below for commit 3:
> Aaaaa
> Bbbbb
> ccccc
> ddddd

How do we know that "Aaaaa" is a modification of line "aaaaa", and not
simply the deletion of the old line and the addition of a new one? It's
easy to come up with a case where that is more obvious:

  -aaaaa
  +ddddd

but there are many shades of gray in between. Is:

  -aaaaa
  +Aaada

the deletion of an old line and the introduction of a new one, or the
modification of an existing line?  So fundamentally the diff format just
deals with added and removed lines, and modifications are represented as
a delete followed by an add.

Which isn't to say you couldn't think of many clever algorithms for
heuristically determining a modification, but git doesn't do that itself
in numstat.

-Peff

```
