Bug by showing last line number in PRs

  1. Go to Add AUR introduction by fossdd · Pull Request #100 · chriswalz/bit · GitHub
  2. See the last line

I guess, cause I added a few lines. GitHub says this line was previeusly line 308 and now 313.

I’m not sure this is a bug. The diff preview shows the line numbers as they appear in a file before and after the changes set is applied. Some changes may add extra lines, while others might delete some lines, so it’s normal to see offset differences in the line numbers for a same line of code across the two panels.

Also, beware that Git supports different diffing algorithms, which might behave differently with different type of files, especially when dealing with lots of hunk changes. It’s not uncommon for diff tools to loose track of some matching lines in the before and after panels, e.g. due to indentation changes which often confuse the diffing algorithm in respect of which unchanged lines match to their counterparts in the after panel.

Line numbers are a hard reference, for each number shown in either panel refers to the actual line number to which the shown line corresponds in each panel — and since diff previews skips entire blocks of unchanged code, they are an important reference for making sense of the changes, especially when the diffing algorithm looses track of before/after unchanged lines/blocks.

Aligning Out-of-Synch Diffs

As a side note: when I’m faced with problematic diffs that loose track of lines correspondence in the before and after panels, I use a diffing tool that supports manually aligning changes or break alignments by selecting a line in one panel and clicking to its counterpart in the other. This operation refreshes the preview panels and corrects any synchronization errors; and the operation can be done multiple times.

I use BeyondCompare 4 for this, and the feature is documented here:

https://www.scootersoftware.com/v4help/index.html?sessiontextmergealignment.html

BC4 is a commercial tool, but I’m sure other good diffing tools offer this feature too, including free open source ones — I just don’t know them, so I can’t provide other examples.

GitHub WebUI doesn’t provide this feature, and to the best of my knowledge neither do most Git GUI frontends. But you can always configure Git (or a specific repository) to use a third party tool for diffing operations, which would improve your working experience locally.

As mentioned before, this misalignment problem has nothing to do with tools being “good” or “poor” quality, it’s just the nature and complexity of diffing algorithms, and there will always be some changes that will confuse any given diffing algorithm.

I hope this helps.