2

I need a solution that shows me the number of rows added, removed and modified from every git commit. For git stats, it displays only the insertions and deletions, but not the modifications. I have not found a solution that could be useful for this problem.

Example

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Leomar de Souza
  • 677
  • 10
  • 23

1 Answers1

1

That question showed up this patch proposal in early 2018.
Philip Wood tried to highlight the concept of "modified lines".
(A simplified version of his patch made it here)

When a set of lines is modified the hunk contains deletions followed by insertions.
To correctly stage a subset of the modified lines we need to match up the selected deletions with the selected insertions otherwise we end up with deletions and context lines followed by insertions which is not what we want.

That ended up to be tricky:

To implement staging modified lines the code needs to pair up each deleted line with its replacement.
It does this by grouping consecutive selected lines together, so it has a list of groups of deleted lines and another list of inserted lines, it then pairs the deletions and insertions by their index in the list.

Philip started to have doubts:

I'm beginning to see why all the other programs I tried while writing this (tig, gitg, gitk and mercurial's version of add -i) don't make any attempt to stage modified lines correctly, though I think Git should have some way of doing it.

Qnd the main maintainer of Git Junio C. Hamano confirmed those doubts, with this answer:

Yes, this is a kind of feature that one can propose and implement something that works well for some of the limited cases one uses, but not in other cases.
And it becomes very hard to explain how to work around the implementation limitation---that is why I stopped at "split this hunk?" and did not go beyond it when I designed the original "incremental add" feature.

I think the real reason why it is hard is that there is no good definition of "modified" in "stage modified lines".
And worse, there is no good way to mechanically figure it out, because a patch only gives you "these were deleted" and "these are added", without giving you "this line in the deleted block corresponds to these two lines in the added block" (i.e. "this original one line was modified into this thing in the result").

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250