This is a huge component of compulsive overeating, and one that's plagued me all my life. I bet if you think about it, it applies to other areas of your life as well. I have a huge perfectionism streak that says, for example, that if I can't completely clean the kitchen in one go so that it looks like a model at Home Depot, then there's no point in washing the dishes. Ya know?
I really have had to teach myself to talk to myself and counter those voices. They never go away -- there's always a voice that says, "Might as well eat what I want the rest of the day since I've blown it" -- but I've learned to answer back in a positive way and shout it down. Most of the time, anyway.
I've also learned to plan around it, to anticipate where things may not go perfectly and have a plan of action. For example, I may know that I'm going out with friends for a birthday lunch for one of the girls. I know that's an opportunity to slip. I don't anticipate slipping, I go to the lunch with a firm plan of what I'll eat. But, I also am mentally prepared to go on with the rest of my day as I should regardless of what happens at lunch -- to the gym after work, eating my normal dinner, etc. The more planning and mental rehearsal I do, the better off I am.
One thing that really helped me to recognize this about myself, and start to turn it around, was the book
The Thin Books: Daily Strategies & Meditations for Fat-Free, Guilt-Free, Binge-Free Living. The author is a member of Overeaters Anonymous, but it's not a 12-step book. Note that she is a vegetarian and part of the book promotes that diet plan, but it's the mind stuff that's the central part of the message.