What helped me was understanding the drivers behind my urge to eat.
Our bodies are made to crave fat and sugar to help us survive famines. Your brain is designed to give you wonderful feelings when you eat fat and sugar. Over time we learn that we can achieve that feeling by eating and then, when we need that good feeling, e.g. when upset, stressed, bored, our brains shortcut to food.
When I crave fat/sugar I try to remind myself that it's what my brain wants me to do. It's not what I want to do. I want to be healthy.
I also remind myself that if I do give in, I'll have maybe a few mins of that good feeling, max, followed by hours of guilt that I caved.
I try to find alternative activities which give me the feelings I'm craving from food, e.g.: cuddles from a loved one, laughter, a lovely bath.
Sometimes if I just really can't get over the craving to eat something, I'll make a tea with milk instead, as it has that tiny bit of sugar you're craving, and is quite filling, without being as bad as eating a whole chocolate bar or similar.
Recently DH and I have also just banned snacks in the house outright on the premise that if we have to go out to get food rather than to the cupboard, we'll be much less likely to do so!