I have been given tons of great advice on how to fix this and you have to find what is right for you. The big one is not to deprive yourself of something you truly enjoy. For me it is chocolate, I feel like I have to have some everyday or my life is empty. Allow yourself a reasonable portion of this food that you are craving and cut it off right there. Allow yourself to truly enjoy that portion you are allowing yourself. How often do we binge on a bunch of junk food and really sit back and enjoy each bite? Probably never.
One bad habit I had to kick in the butt was just grazing and mindless eating. The thing that solved that for me was sugar free gum. I have a major sweet tooth and the right kind of gum satisfies my sweet tooth and keeps me away from the cookie jar. If I need to stop myself form grabbing food I drink water and pop in a stick of gum and I"m happy until the next meal/snack.