What a diff algorithm is actually solving
The obvious approach, comparing line one to line one and line two to line two, falls apart the moment a line is inserted. Everything after the insertion shifts by one position, so a one-line change reports the entire rest of the file as different.
What you want instead is the longest common subsequence: the longest ordered set of lines that appears in both versions, not necessarily contiguously. Lines in that sequence are unchanged. Everything in the old version that is not in it was removed, and everything in the new version that is not in it was added.
This is why a good diff of a file with one inserted line shows exactly one added line, no matter how much text follows it.
before after result
----------- ----------- ------------
alpha alpha unchanged
beta inserted + inserted
gamma beta unchanged
gamma unchangedThe same idea drives git, code review tools, and the Unix diff command. They differ mainly in how they present the result and how they optimise the search.