This has been a huge problem for me, too! It's the one habit that, in the past, has derailed attempts to lose weight because afterwards I just feel like I might as well give up. Luckily, I've learned to just move on and tell myself that the next day is a brand new day.
The way I stop myself from binging is just by telling myself that the five minutes I spend eating that sugary bowl of cereal (I love eating cereal at night, for some reason...especially Coco Puffs!), or whatever it may be, is not worth all the damage it'll do to my progress. I think about the fact that what I want to eat in that moment is really just another obstacle that will prevent me from getting the body I want and being able to wear the clothes I've always wanted to wear, which is far more important to me than a bowl of Coco Puffs. I also remember that the food is satisfying for those few minutes, but after I've eaten it I never feel satisfied or as if it was worth it.
If haven't gone over my caloric limit for the day, I sometimes just have a healthy/relatively healthy snack that takes the edge off the craving. For example, if I'm craving something sweet, I might have some yogurt or a small bowl of maple syrup-flavored oatmeal. If I'm craving something salty or savory, I might have a few (two or three) crackers with tuna and a bit of Miracle Whip spread on them, or even just some tuna or pink salmon alone right out of the can!