When I look at code I intend to edit, there are a number of goals I want to accomplish. Each time I edit, I try to accomplish only a single goal, but sometimes I get going and find myself in a hole.
Some of the different goals I have regularly are: gardening the code up to current coding standards, clarifying the code purpose for other viewers, fixing a bug, removing deprecated code, and adding new and exciting features.
For older files, I often find myself tempted to accomplish many of these goals at once, and if the issues are complex, this just doesn't work out. I find myself in a place where the important goals have not been accomplished and the less important goals are basically irrelevant. It's time to revert all changes and start again.
This happens to me about once or twice a month, because I am very mindful of this situation and like to be in and out of a file in a very short period of time. Small stable changes lead to the best results.