When publishing, Sandvox keeps a record as part of the document as to what it has uploaded to the server. Upon the next publish, it can easily consult this record to see what changes have occurred, and upload only them.
But here's the trick: once you've published something to the internet there's no way to "undo" it; you can only delete it or overwrite it. Similarly in Sandvox, once published there is no sense in undoing changes to the publishing record; to do so would make no change to the server, and would leave Sandvox with the wrong information come the next publish.
Since the publishing record is part of the document, and we don't alter documents on disk until explicitly asked to do so (i.e. the act of saving the doc), the sensible solution is to clear out the undo manager's history upon publishing. Which is where we finally hit upon the point of this post: how to do just that!
“How hard can that be Mike?”, you ask. Well, there are a few caveats. So without further ado, here's a good general purpose snippet: