You lose all your troops when you retreat, no matter when it happens. If you retreat during a battle and have 300 troops left, you will have 0 troops afterwards. I really don't like the system, but I've heard some good arguments as far as why they do it this way (rather than the way it was in the past where you kept a % of troops left).
But the fact you still keep a lot of gear seems really dumb. if you have 0 troops and 1000 crates worth of gear, you're obviously a sitting duck to be attacked again. I'd propose that you don't get any gear either if you retreat.