The undo history isn't saved in the XCF.
IMHO basing youyour workflow on undo is very dangerous, because with a single mistake you can lose a good chunk of your edit history (not speaking of scripts that may have a cavalier attitude with the undo stack). You are also stuffing memory with undo steps that you don't need.
Instead you can keep copies of layers (put them all in an invisible group) and selections (Select > Save to channel
).