No spoiler tag needed for this one, as everyone knows there's a big battle.
We know that when the Army of the Dead is moving in a big mass they tend to miss solitary living people that are out of sight - that's how Sam survived the Fist of the First Men, by cowering at the bottom of a standing stone as they marched past, and waiting until they were gone before getting back up.
You have to know that in the morning there's going to be a few stragglers walking up a bit glassy eyed with tales of how they were buried under a pile of dead people or were knocked out Bilbo Baggins style (or Imp style, if one likes) during the battle and ignored by the dead.
A few things in the battle that I liked and made sense:
The Unsullied held the ranks of their formations and weren't shaken even under the heaviest onslaught, maintaining discipline the whole time.
Considering their whole purpose and training was to defeat the Dothraki, it makes sense that a mass charge against them would generally fail.
When given the order to retreat, it meant an ordinary withdrawl in good order, not a rout like everyone else.
This explains to the fire trench behind them. Nobody thought they'd stand their ground that long; so when the regular folks all ran into the castle (and it was time to light it) they were on the wrong side of the final protective line before the wall itself.
Greyworm gets a serious ding for closing the ditch with Unsullied on the other side yet. He should have given them the order to retreat through it.
Still, even at the end of the battle with the Army of the Dead defeated, there were still Unsullied out there in the middle of the horde thrusting away behind their shield walls.
Speaking of Sam, right about now anyone who starts popping wise about how he doesn't belong in a battle should be immediately corrected. #%&*$#, how many certain death situations does he have to actively survive in order to get some respect? Between defending Castle Black and now the Battle of the Long Night, one would think he's earned his due.
Did Gilly and little Sam survive the crypt? I don't remember seeing them at the end.
The opinions of this poster are largely based on facts and portray a possible version of the actual events.