Don't beat yourself up over giving in. That isn't going to do anything except convince you that you're rubbish at this and lead you to eat more. You need to understand WHY you ate. What were you feeling? How did you rationalise it? When you know what your rationalisation is, you can counter that before it happens. I already know what I will tell myself when I want to cave, 'it's only protein, it won't knock me out of ketosis, I'm hungry, it's better than carbs' but I also know the answers. It's protein that I don't need, and if I'm not hungry and don't need it then I want it for another reason. That other reason will still be there if I eat this, and then what will I do?' I then address what's going on (boredom, tiredness, emotional eating, frustration) and go off and find a healthy outlet. I've only been doing it for 2 weeks but yesterday I held a can of tuna in my hand and put it down again. Tuesday I cooked up a batch of frozen breakfasts for my boyfriend and handled eggs, peppers, sausages etc and used that thinking to keep me on track. You need to recognise the harmful thoughts, and that only comes from facing up to them and analysing them. Most irrational thinking (like for example, oh I've eaten this piece of ham, I might as well order a pizza) don't stand up to logic, so use the logic against them!
We wouldn't be here if we didn't have a messed up relationship with food, and these weak moments are the ones that really give you an insight. They're not disasters, they're learning opportunities.