git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git diff

From
Jeff King <peff@peff.net>
Date
Jan 17, 2011, 22:30 UTC
Message-ID
<20110117223021.GA31045@sigill.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:
Show 5 quoted lines
> 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:
Show 14 quoted lines
> 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
Previous: Carter Lamb
Message 2 of 2 in “git diff”
  1. Carter LambJan 13, 2011
  2. Jeff KingJan 17, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.