I think you can work with the patch utility. This creates the difference between two texts (or files) only in the form of changes. Then the created patch can be saved in the database. You still need the original text, and then all the corrections to the latest version.
For PHP, the xdiff extension can be used to create differences for text and files.
Saving DIFF in the database
To preserve the differences in the database, you need to preserve the order of differences, the contents of diff and the source text.
I assume that you are already saving the source code. You can then save diffs to a difference table containing a link to the source text and an auto-increment key to keep the order next to the contents of the diff text. Then you need to insert one diff after the other in the correct order and be fine.
To recreate the current version, request the original version and all ordered data. Then apply one diff after another to get the version you would like to get.
Alternatively, you can also create another table containing a specific audit result to prevent multiple cycles from repeating over and over. But then it will make the data inside the database redundant.
hakre source share