Retcon or Retroactive Continuity is a term for reinventing the history or intentionally changing the understanding of previously stated facts in a work of fiction. It is often done to resolve a discrepancy that was not originally apparent to the writers but may also be a deliberate act to open up new story possibilities. The critical feature of a retcon is that the facts are not changed, only the interpretation of them.
For example, on Cheers, Frasier Crane mentioned that both his parents were scientists, and that they were both dead. When the character moved to his own series, Frasier, his father was very much alive, and a former police officer, not a scientist. Well into the run of the series, Frasier is confronted with this fact. He explained that he was angry with his father at the time, so he lied about him. It is assumed that Frasier's previous statements about his dead father were not taken into account when the spinoff was created, and that the later explanation is a retcon.
Note that a fan wank differs from a retcon in that retcons are written into the story, whereas fan wanks are merely stated by the writers (or fans) to the fans and/or media.