I've found that many techniques from REBT (Rational Emotive Behavior Therapy) have been useful to me in keeping to a healthy food and exercise plan as well as making me a happier person overall.
The main REBT technique that has helped me is identifying and disputing irrational beliefs that make me very unhappy and result in behaviors I don't like. It uses an A-B-C framework. A=activating event, B=belief, C=consequence.
We usually think of events (A) causing results (C):
A: I'm at a cafe, see some delicious fresh-made pastry, and get an overwhelming craving for some with my coffee even though I've had plenty to eat and am not hungry.
C: I give in and get the pastry and eat it.
But did A really cause C? REBT says no, there is a B, an irrational belief that caused me not to do what I know I should and would prefer to do (not order the pastry). REBT encourages you to dig deep and figure out why. In my case there might be several irrational beliefs:
B1: I will feel terrible and awful if I don't eat the pastry and I won't be able to stand it!
B2: It's SO UNFAIR that I can't eat what I want when I want it and I can't stand it! Life SHOULDN'T be unfair!
B3: I SHOULDN'T crave food every time I see it! I'm a weak, pathetic person.
The next step of REBT is D="disupting". I then actively dispute the beliefs.
D1: Is it really true I wouldn't be able to stand it? Will I actually die if I don't have the pastry? Would I have even felt the urge if the coffeehouse had been out of pastry that day? Haven't I gone without food before and survived? I have zero evidence that "I couldn't stand it" (I'm still alive!), and lots of evidence that, yes, I CAN stand it. It might not be pleasant, but it's not terrible, horrible, and awful!
D2: Who am I to dictate how life should be, am I god? Don't I have lots of advantages that other people don't have? Is that fair?
D3: I am who I am. I can't be other than I am right now and the workings of the brain are poorly understood. Just because I get a desire for something doesn't make me weak or pathetic, it just makes me human.
If one is successful at finding the irrational belief that is really driving one's actions (and sometimes it's not obvious and takes several rounds of doing this technique) and successful in disputing the irrational belief and getting myself to see this, it gets replaced with a new E: effective belief.
Perhaps:
E: It's unpleasant to have to experience unsatisfied desires for the pastry and give up the short term pleasure, but it's not terrible, horrible, and awful and I CAN stand it. It would be nice not to be subject to such urges, but sometimes life isn't nice and I just have to deal with it. I'd also prefer that life was fairer, that I could eat whatever I want, or that I didn't get strong urges, but again, it's not terrible, horrible or awful, and I CAN stand it. That I get urges for such things doesn't say anything about my character, that would be silly.
By replacing the strong irrational beliefs which "awfulize" the urge with a gentler one that recognizes the reality of the urge and merely expresses my preference that things be otherwise, C need not happen even though the urge did. I wrote C above as "give in and eat the pastry", but it could also be "I don't order the pastry and get angry and upset", which is also not a good outcome. Disputing irrational beliefs also helps diffuse that "angry and upset" result in the cases where I am successful in not ordering unhealthy food for me. So the new outcome becomes "I don't order the pastry, and feel some disappointment at not getting to fulfill the urge, but don't feel angry and upset about it".
The ABC technique is the cornerstone of REBT, but there are many other coping with urges tools, including many for preventing them. And there is a site that has collected many of the tools together and worksheets for addressing them:
http://www.smartrecovery.org/resources/toolchest.htm
These were pulled together by SMART Recovery which is an alternative/adjunct to AA and mostly focused on helping people overcome substance and alcohol abuse, but is helpful for any chronic problem behavior.
One of the best books on REBT generally is by the psychologist who formalized the theory and is _A Guide To Rational Living_:
http://www.amazon.com/Guide-Rational.../dp/0879800429