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

Re: Git has two ways to count modified lines

From
René Scharfe <l.s.r@web.de>
Date
Apr 2, 2022, 21:55 UTC
Message-ID
<d650bb90-df94-eeab-0684-ee447e080ad6@web.de>
In-Reply-To
<CAB1LBms3F1EGswxF9mO=JrmWmj4XFncv4ZrkAy-dvOHdVrkwLQ@mail.gmail.com>
Am 02.04.22 um 18:49 schrieb Laurent Lyaudet:
Show 6 quoted lines
> Le mer. 16 mars 2022 à 19:08, Laurent Lyaudet
> <laurent.lyaudet@gmail.com> a écrit :
>>
> I thought my email was sent to the right mailbox, at least it is what
> says this website :
> https://git-scm.com/community
Sure it was.
Show 8 quoted lines
>> General questions or comments for the Git community can be sent to
>> the mailing list by using the email address git@vger.kernel.org.
> Moreover this website is cited in the README here :
> https://github.com/git/git/blob/master/README.md
>> Many Git online resources are accessible from https://git-scm.com/
>> including full documentation and Git related tools.
> Is there any problem with my questions explaining I got no answer,
> please ?
Not really, don't worry.
Show 7 quoted lines
> I have found a partial explanation for the count differences :
>>  2 files changed, 88 insertions(+), 48 deletions(-)
>>  rewrite src/apps/logs/components/PresenceList.js (61%)
> When committing, a file considered as "rewrite" is counted like m
> lines deleted and n lines added if it had m lines before and n lines
> after.
> Even if the diff is much smaller.

Git stores the file contents before and after your change. It doesn't store any diff, but calculates them as needed, e.g. for the commit confirmation message, or when you run git diff. So in that sense there is no "the diff". The difference between two stored states can be represented in many ways.

> Hence I answered my question :
>> How can I check how it computed these numbers in the first place ?

The option --break-rewrites controls rewrite detection. Check out its description in the documentation of git diff to see how to use it.

> But the two other questions remains :
>> How comes git has two ways to count modified lines ?
> i.e. What is (was) the purpose of this rewrite counting (when coded) ?

Rewrite detection is meant to improve the diff of a file whose content was replaced with something very different. Instead of lots of hunks containing lines that add and remove unrelated stuff, separated by empty lines etc. that the diff algorithm matches between the sides even though they are also unrelated, a rewrite diff removes all the old lines en bloc and then adds all the new ones, which is easier to read in that case.

>> How can I make git output again the same numbers than just after commit ?
git show --stat --break-rewrites

But I have a question to the list as well: Why is break_opt (the diff_options member for --break-rewrites) enabled for git commit by default? I ask because the last commit that mentioned it, dc6b1d92ca (wt-status: use settings from git_diff_ui_config, 2018-05-04), claimed it would turn it off, if I read it correctly.

René
Previous: Laurent LyaudetNext: Laurent Lyaudet
Message 3 of 7 in “Git has two ways to count modified lines”
  1. Laurent LyaudetMar 16, 2022
  2. Laurent LyaudetApr 2, 2022
  3. René ScharfeApr 2, 2022
  4. Laurent LyaudetApr 5, 2022
  5. René ScharfeApr 4, 2022
  6. Ævar Arnfjörð BjarmasonApr 5, 2022
  7. René ScharfeApr 5, 2022

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.