Text Diff in Practice: Legal Redlining, Code Review, and How AI Writing Assistants Show Changes
Legal document redlining, Git pull request review, Word's Track Changes, and AI writing assistants all use the same diff principle. Here's how each context uses comparison differently, why legal diff needs more than plain text comparison, and how AI tools use diff to show suggested edits.
By sadiqbd Β· June 11, 2026
Legal document redlining works on the same diff principle as Git β but the consequences of missing a change are very different
In software development, a diff shows you what changed in a pull request. In legal practice, a "redline" or "blackline" shows what changed between contract versions. In both contexts, the fundamental operation is identical: compare two versions of a document, identify insertions and deletions, and display them clearly.
The difference is the stakes. Missing a changed clause in a contract might commit a company to terms it didn't intend to agree to. Understanding how diff tools work in different professional contexts, and how AI writing assistants have begun using diff to show suggested changes, makes the comparison operation more powerful in practice.
Redlining in legal documents
Legal document comparison is known as "redlining" β insertions are traditionally shown in red (or underlined), and deletions are shown with strikethrough (or in a different colour). Major legal document management tools (Kira, iManage, NetDocuments, Litera Compare) are built around this comparison operation.
Why legal redlining is more demanding than code diff:
- Legal documents use formatted text (bold, italic, indentation) β changes to formatting matter, not just content
- Tables, headers, footers, footnotes, and cross-references must be handled correctly
- The document structure (clause numbering, section hierarchy) must be preserved in the comparison
- The comparison needs to identify when entire clauses have been moved (relocated) vs. deleted and separately added
Common legal redline scenarios:
- Comparing the latest contract version sent by counterparty to your last draft
- Comparing a term sheet to the final executed agreement
- Comparing a template agreement to a customised version
- Regulatory filings: comparing a prospectus draft to the final version
Track Changes in Microsoft Word: diff inside the document
Word's Track Changes is a built-in incremental diff system. Rather than comparing two separate files after the fact, Track Changes records each change as it happens, who made it, and when.
The difference from external diff:
External diff (comparing two completed documents): shows what the final result is, not who made which specific change or in what order.
Word Track Changes: preserves the editing history β each author's insertions and deletions are individually attributed and can be accepted or rejected one by one.
The data structure behind Track Changes: Word's XML format stores accepted and pending changes as overlapping layers. An accepted edit is part of the document body. A pending tracked change stores both the original and modified versions, with metadata (author, timestamp), and the display layer shows both.
Accepting and rejecting changes:
- Accept All: merges all tracked changes into the final document
- Reject All: reverts to the original pre-tracking version
- Accept/Reject individually: allows case-by-case review
Code review diff: GitHub, GitLab, and what the interface shows
Pull request / merge request diff views in GitHub and GitLab build on the same line-based diff algorithm but present it in a UI optimised for code review.
Unified vs. split view:
- Unified: a single column showing the file with removed lines in red (prefixed with
-) and added lines in green (prefixed with+) - Split (side-by-side): the original on the left, the modified on the right, with matched lines aligned
Hunk headers: diff output is divided into "hunks" β continuous blocks of changed lines. Each hunk shows a context header like @@ -15,7 +15,9 @@ meaning "starting at original line 15, showing 7 lines; in modified file, starting at line 15, showing 9 lines."
Commenting on specific lines: GitHub's PR review interface allows comments on any specific line in the diff. This is the primary mechanism for code review: reviewers click the + icon on any line to add a comment specific to that change.
Suggestion feature: GitHub and GitLab allow reviewers to propose specific text changes as "suggestions" β the author can accept a suggestion with one click, which creates a new commit with that exact change. This is a diff-in-reverse: the reviewer creates the "after" state, the tool computes the diff from the current state.
AI writing assistants and diff display
AI writing assistants like Grammarly, ChatGPT Canvas, Claude's artifact editing, Notion AI, and similar tools have increasingly adopted diff-style displays for suggested edits.
The flow:
- User submits text for editing
- AI returns a suggested revised version
- Tool computes a diff between the original and the AI's revision
- Diff is displayed: deletions in red/strikethrough, insertions in green/underline
- User accepts, rejects, or selectively applies changes
This display pattern solves a real UX problem: showing the entire revised document would make it easy to accidentally miss a change the AI made. Showing only changes (as in a diff) makes the actual modifications immediately visible.
The challenge of semantic diff: AI-generated suggestions often restructure sentences, not just insert or delete words. A sentence rewritten from passive to active voice looks, to a character-level diff algorithm, like a deletion of most of the sentence and insertion of entirely new text. Newer tools use word-level and sentence-level diff algorithms to produce more legible comparison views.
Comparing documents outside of dedicated tools
Command-line diff:
diff original.txt modified.txt
diff -u original.txt modified.txt # Unified format (more readable)
diff output reading:
--- original.txt
+++ modified.txt
@@ -1,4 +1,5 @@
Line 1 (unchanged)
-Old line 2
+New line 2
+Added line
Line 3 (unchanged)
Line 4 (unchanged)
Comparing Word documents from command line:
# Convert to plain text first
pandoc original.docx -o original.txt
pandoc modified.docx -o modified.txt
diff -u original.txt modified.txt
How to use the Text Diff tool on sadiqbd.com
- Paste original text in the left panel
- Paste modified text in the right panel
- Run comparison β see insertions highlighted in green, deletions in red
- Use for:
- Comparing two versions of a document or email
- Verifying a vendor's contract changes against your last draft
- Checking whether a web page has changed (paste before/after HTML or scraped text)
- Reviewing AI-generated edits against original content
Frequently Asked Questions
Can I compare formatted documents (Word, PDF) with a text diff tool? Text diff tools compare plain text β formatting differences (bold, font size, tables) are not captured. For formatted document comparison, use dedicated tools: Word's built-in Compare Documents feature (Review β Compare β Compare), Adobe Acrobat's Compare Documents (for PDFs), or specialist legal redlining tools like Litera Compare or DocuSign CLM.
What is a semantic diff and how does it differ from line-based diff? A line-based diff treats the document as a sequence of lines and identifies which lines were added or removed. A semantic diff understands the structure of the document (code syntax, markdown structure, sentence structure) and can identify more meaningful changes β a function being renamed vs. a function body being changed, for example. Semantic diffs are more useful for reviewers but computationally harder to produce.
Is the Text Diff tool free? Yes β completely free, no sign-up required.
Text diff is a fundamental operation that appears in tools across legal, editorial, software, and AI contexts. The underlying algorithm is the same β what changes is the presentation, the granularity, and what counts as a meaningful change in each domain.
Try the Text Diff tool free at sadiqbd.com β compare any two texts and see exactly what changed, with insertions and deletions highlighted clearly.