It seems fairly common on here that people ask questions regarding armies of foot soldiers clashing, often coming in with the misconception that it was the sort of wild, brutal, charging melee depicted in films; when in reality it was likely (based on records of multi-hour battles with relatively light casualties, as well as study and experiment by modern enthusiasts) that it was much less messy.
In addition, everyone knows about the lance-charge and the devastating effect cavalry could have on infantry.
However, there are also many records of battles in which cavalry fighting cavalry, both in pre-modern and modern (18th, 19th century, etc) eras, for comparable lengths of time as the infantry; not to mention cavalry charging infantry and seemingly remaining "stuck in" after the charge. Certainly if the enemy is scattered, a horseman has a huge advantage; but how would a formation of riders handle a formation of footmen which didn't break on the initial contact?
What is known about how these engagements were handled? Did cavalry combat devolve into wanton swords-swinging, as a film might depict? Did it become a more ordered, shield-wall-esque affair? Was it something else entirely?
While there is no academic consensus on use of cavalry in the micro level, there is some theories and facts. There seem to be two main ways of conducting a cavalry charge in history. Main difference is how horses run, gallop or trot. Galloping cavalry cannot keep a tight formation, and are forced to leave more space between horses. Trotting cavalry can form up tighter, knee to knee, or even closer in a wedge knee behind knee. To mitigate looseness caused by gallop many cavalries trotted very close and used gallop only on the last moment.
Medieval knights used mainly last moment gallop technique. Formations loosened up before opposing cavalry lines met, due to gallop, terrain differences and horses and riders avoiding collision with each other. When lines meet they will pass each other, and lances were used to kill enemies. Alternatively one side can chicken out and be routed before contact. Either a chase, a melee or reorganization and repeated charge follows contact.
Trotting cavalry, like Byzantine defensores cavalry units in 6th century or most early modern European cavalry, charged trotting. This allowed them to keep tight formation. Lines formed up knee to knee cannot pass each other. It seems that in cases where neither side is routed before contact, horses and riders stop in front of each other, since horses won't ride into collision and riders aren't suicidal. This would be followed by slower last meters and melee, or retreat and a new attack.
Infantry v cavalry combat is as poorly understood as cavalry v cavalry combat. Byzantine military manual authors thought that infantry formations are too hard to break by cavalry charges, forbidding frontal attacks. They went even so far as to recommend dismounted defense for outnumbered cavalry units that cannot escape from enemy cavalry. Success of a cavalty charge against a tight infantry formation is dependent on infantry routing or there being a gap in the line to exploit. Flank and rear attacks were easier.
Examples:
At Hastings in 1066 Norman knights were unable to break English shield wall until the English charged after retreating Norman cavalry.
At Iconium during the first crusade Norman knights dismounted and were able to defend against superior turk cavalry until reinforcements arrived.
In an engagement in the Peninsular war Kings German Legion cavalry broke three French infantry squares by exploiting a holes made by a shot and dying horse and escaping French soldiers. At Waterloo French cavalry was unable to break a single British square.