Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show revision history like revisions

How does Stack Overflow show the revision changes in the diff-like format they use?

I don't care about Stack Overflow per se; it's just a convenient way to describe my requirement. I have an audit history of changes to a text field. I'd like to show the changes the same way Stack Overflow shows revision history changes. I recall a Stack Overflow podcast where Jeff Atwood discussed it, but I can't find it in the transcripts and have no idea what podcast. IIRC, it's not .NET based, maybe Python?

This is for end-user consumption so anything that looks like a Unix-like diff is out. It is tempting to show two blocks and text, old and new and let them figure it out, but the Stack Overflow revision history is sooo much nicer.

like image 694
Walden Leverich Avatar asked May 28 '09 21:05

Walden Leverich


People also ask

How do you do revision history?

Go to File > Info > Version History. Select a version to open it. If you want to restore a previous version you've opened, select Restore.

What is document revision history?

Revision history allows you to see what was revised, who made the revision, compare two revisions, and revert to another revision if necessary. You can see Revision History for all content pages made from new page templates and within template directory such as header and footer templates.


2 Answers

The Python difflib standard library provides this sort of capability:

This module provides classes and functions for comparing sequences. It can be used for example, for comparing files, and can produce difference information in various formats, including HTML and context and unified diffs. For comparing directories and files, see also, the filecmp module.

like image 131
Greg Hewgill Avatar answered Nov 30 '22 16:11

Greg Hewgill


Since you didn't really specify a language: I've done this using the PHP PEAR package Text_Diff.

like image 21
Paolo Bergantino Avatar answered Nov 30 '22 16:11

Paolo Bergantino