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

Re: Git has two ways to count modified lines

From
LLLaurent Lyaudet <laurent.lyaudet@gmail.com>
Date
Apr 5, 2022, 15:57 UTC
Message-ID
<CAB1LBms-Urzbx=Q=9Ydvsrgx=6si+FwZa09MEz9zCHRser8iuw@mail.gmail.com>
In-Reply-To
<d650bb90-df94-eeab-0684-ee447e080ad6@web.de>
Le sam. 2 avr. 2022 à 23:55, René Scharfe <l.s.r@web.de> a écrit :
Show 5 quoted lines
>
> Am 02.04.22 um 18:49 schrieb Laurent Lyaudet:
> > Le mer. 16 mars 2022 à 19:08, Laurent Lyaudet
> The option --break-rewrites controls rewrite detection.  Check out its
> description in the documentation of git diff to see how to use it.

Hello everyone, Thanks René, I checked and now I understand how it works :)

Show 11 quoted lines
> > 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.
It makes sense to produce diffs simpler to understand.
From my experience, humans are better than computers at knowing when
to "break-rewrites" (or see that a line was moved, etc.) .
I have dreamed about hinting the diff tools for many years,
but I'm more used to simply accept what the computer produces as its
diff(s) and have my own analysis that does not match.
Maybe for git 10.0, someone will add metadata in commits for human
optimized diffs :)
For applying patches, it is useless but for understanding code change, it helps.
At least, it is a good mental exercise.
Just in case, if someone cares, in my notebook I note the following counts :
- non empty and not space only created lines
- empty or space only created lines
- modified lines (non space created or deleted character)
- space modified lines (but I should split this category between space
presentation, and space bug related (Yes you can correct bug by
changing only spaces, most of the time in strings)
- moved lines :
   - as is
   - with space modification
   - with non-space modification
- non empty and not space only deleted lines
- empty or space only deleted lines
> >> How can I make git output again the same numbers than just after commit ?
>
> git show --stat --break-rewrites
Thanks :)
Best regards,
    Laurent Lyaudet
Previous: René ScharfeNext: René Scharfe
Message 4 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.