It is a mistake to suppose that men succeed through success; they much oftener succeed through failures. Precept, study, advice, and example could never have taught them so well as failure has done. (Samuel Smiles)

Not every idea leads to a success, and not every first draft forms a good template for the final draft. This is true even for the very best mathematicians.

There are times when a project just isn’t working the way it was initially planned, and you have to scale it down, refocus it, or shelve it altogether; or a lemma that you spent a lot of time on turns out not to add anything much to the paper and has to be reluctantly jettisoned or deferred to another paper; or that the structure of a half-written paper is clearly not optimal and that one needs to rewrite the entire thing from scratch. (Indeed, some of the papers I am most proud of are virtually unrecognizable from their first draft, due to one or more complete rewrites.)

One has to know when one should be persistent and patient, and when one should be pragmatic and realistic; stubbornly working away at a dead end is not the most efficient use of your time, and publishing every last scrap of your work is not always the best way to meet the standards of quality you expect from your publications (though sometimes it is still worth making your partial successes available in some format). Of course, in today’s digital age it is cheap and easy to backup all your work, and you should certainly do this before performing major surgery on any paper.

Even an embarrassingly wrong piece of work (and I have a number of these, which fortunately have never made it as far as publication) should be stored privately somewhere, because you never know whether something salvageable can be extracted from it, and also it is good to make a note of mistakes that one should avoid in the future. For instance, it can help you learn the limitations of your own tools.