Yes as Leledumbo say, is the best way.
In some programs also selecting a layer is an undo/redo action. Corel Photo Paint and Photoshop store all the actions, then you can save those as a macro or script, and then you can recreate the whole image from those files, select the 'point' where you want to re-create, is a list of undo/redo actions.
- New File (640x480)
- Fill gradient (colors, position, etc)
- Twirl Filter (...)
- Import layer (box.png) >> for example you can clic this item in the list and go back to this point
- Select layer
- Rotate layer 180
It search the filenames i don't remember if in a full path or a relative path...