There are many stages of awareness and understanding of how to eat healthfully (not to mention a variety of ideas about what that means!), but once we have chosen a path towards supportive eating, there is still the issue of actually making the right choices in the moment.
The first step to shifting a habit of eating foods that we know are not supportive to fitness and health is to recognize what is happening when we veer away from making the choices we had planned. The key is to gather enough consciousness in that moment of choice-making to stop, and have planned in advance some activity or something you can say to yourself to remind you that you have a choice here. When you notice yourself falling into whatever it is that sidetracks you (anger, loneliness, impatience, etc.), you might say “Oh, yes, here I am again at that point where I could start to go wrong. Let me see if I can make a better choice this time.” You might write in your journal, or read something inspiring, or go for a walk, or take a few deep breaths and remember the things you are grateful for, or whatever else you can imagine might help you stay centered and able to make a conscious choice.
Just remember that you can become aware, you can take some deep breaths and you can tell yourself that a small step in the right direction AT THAT MOMENT can make a difference.