To save your undo trees in a separate file, use :wundo and :rundo.

Example:

After editing hello.txt, I can save my undo tree with

:wundo! hello.undo

Close vim. Open hello.txt. We can't undo. This is normal. Now read undo file:

:rundo hello.undo

You can undo now.

source