The escaping gas of a comet creates a sort of atmosphere around the nucleus, which is called the coma. The comet nucleus' gravity is very weak, so that the thermal motion of the gas atoms is already sufficient for them to break away from the nucleus' gravitational grip.
While the density of neutral gas atoms is high enough to make collisions between them frequent close to the nucleus, the gas gets more tenuous farther away so that collisions become very rare events, and it is like each atom moves along its own path without interference from the other atoms.
Solar radiation gives rise to comet plasma tail
At the same time, however, this neutral gas becomes ionized by solar UV radiation, like in the Earth's ionosphere. On their motion outward, these ionized particles meet the solar wind plasma, thus forming the cometopause, the interface between solar wind and cometary material.
The motion of the ionized cometary gas then becomes determined by the interplanetary magnetic field, and the cometary ions and electrons are gradually "picked up'' by the fast anti-sunward flow of the solar wind.
Comet's plasma tail orientation
Remember that the plasma is so tenuous that there are no collisions between solar wind particles and the cometary particles, so the solar wind does not force the cometary plasma to move along by friction; the two types of material interact only through the magnetic field.
This gives rise to the comet's plasma tail, which points radially outward along the Sun-comet line. It was, in fact, the existence of such tails that led Biermanto infer the existence of the solar wind.
Disconnected plasma tail
The structure of the plasma tail is clearly determined by the interplanetary magnetic field. One manifestation of the role of the interplanetary magnetic field are disconnection events.
When the comet passes through the heliospheric current sheet (that is, informally speaking, the magnetic equatorial surface in the solar wind; the interplanetary magnetic field points sunward on one side of it, and anti-sunward on the other side), the reversal of the magnetic field direction leads to a polarity reversal in the plasma tail. What happens is that the original tail is "cutoff'', while a new plasma tail with the new polarity starts to form.
An example is shown in the accompanying figure, where the old plasma tail is disconnected from the coma (it begins in the middle of the picture, there is no plasma tail between the coma and this point); the ray-structures (straight lines) immediately behind the coma are typical for the early stages in the formation of a new tail.