You got two options for an Undo Management System (UMS):
(1) Save a copy of image for each modification. To make an 'undo' you go to your UMS and request the previous image state.
(2) Keep track of the modication done each step from the original image onwards, only store info needed to reproduce the change. To make an 'undo' you go to your UMS which applies all operations 'fast forward' from original up to the requested level.
For an advanced UMS you may combine these two options by recording info about all modifications, and only occationally store full cache image. Then
UMS may decide the most efficient route to return the image state level requested.
The easiest and most basic 1-level UMS is to just store a copy of previous image state.