Hm I think I know what you mean. What I recommend is NOT giving into those cravings for at least 2 weeks. No cheat days, nothing. Remind yourself that people have lived and died without cookies and cake, and its not the end of the world if you go without it for a couple weeks. That usually gives me a clearer mindset and makes me feel confident because I can go that long without the sweets.
And on days where you do eat too many of those things, I recommend the next day not eating at maintenance but JUST below maintenance, maybe 100 cals so that it'll boost your confidence - like "hey I can eat at a deficit" without feeling like its too drastic of a change.
But first and foremost, feeling calm helps the most. I would constantly panic and go on and off the "bandwagon" but when I steadied myself and told myself to just move on and calmed down until I no longer felt panic, it really made a big difference.
I listened to my gut and it said "You could do with less of me."