Apex › Storage & databases

How diff works (git diff, code review)

The algorithm behind git diff, code review, and patch. A diff is the smallest set of line inserts and deletes that turns the old file into the new — found by taking the longest common subsequence (the lines that stayed) and marking everything else + or −. Pictured as a shortest path through an edit grid: a diagonal is a free “keep,” right is a delete, down is an insert. Real LCS diff; Myers’ O(ND) is the fast version git uses. Pick an edit and watch the diff and its path recompute.

More in Storage & databases