Indeed nobody knows for sure how they did it, and here I have read some very good ideas.
My imagination is that the hastati and principes were in a relatively loose order, with a space for a soldier of about 1,80 m. The two centuries of the maniple advance one behind the other, so they can manoeuver easily and avoid hindrances (unlike a phalanx). The centuries of the principes were normally behind the gaps between the hastati maniples, if not exceptionally (like at Zama) they were behind the hastati.
Before the attack and after the velites returned the rear hastati century can turn and march in the gap, if a closed front line is desired. In one of the pauses of the fight they can turn and march behind to allow the principes to come to the front. Or, perhaps the safer version, the soldiers can shorten the distance between each other (from 1,80 to 0,90 m), with one side as the base, which will create century wide gaps in the front. Instead of turns and backmarching (difficult) only sidesteps were necessary. To have different spaces for the soldiers for different situations was also a method for the Greek phalanges.
Another possibility is that the centuries were beneath each other from the beginning and the legio fights with gaps in the front line. I don't have such a good feeling with this, but I know that some excellent scholars prefer this version.
I don't believe that the individual rows were changing during the fight (like in "Rome", part one) or the first rows were attacking repeatedly. To move like this in the thick of fray would have been very dangerous for the order and prone to disaster.
Bookmarks