This is an excellent question! I don't think that I can answer it definitively, but the following information might be of use to you. If you have a look at Avraham Grossman's Rashi (trans. Joel Linsider; The Littman Library of Jewish Civilization, 2012), you will see that he features a bit of a discussion of this issue on pp145-147.
He quotes various scholars who have also noted Rashi's inconsistencies and contradictions, and who were not bothered by them. One example is the Maharsha (Kiddushin 44a, s.v. כלל אינו), who observes that it is a basic feature of Rashi that he explains things differently in different places.
One theory has it that Rashi sometimes changed his mind, while another had it that the information transmitted pertained to things that he had learnt from different teachers. One novel (but problematic) theory has it that the commentaries were transmitted orally to his students and written by them, but this is dismissed by Grossman on the basis of the manuscript evidence, which clearly seems to show that they began as literary compositions.
Grossman lists four different possibilities: the possibility of scribal error, Rashi's own corrections (which may not have covered the entirety of his work), his reliance upon different teachers at different times, and the need in some instances for a contextual interpretation - that is, reflective not of Rashi's personal opinion, but of what he believes the opinion of that particular sugya/sage to be.
Since there is evidence of multiple manuscripts of Rashi's commentary on individual tractates, testifying to the fact that his work was updated and corrected, I think it's reasonable to suppose that the considerations that Grossman lists are all relevant to Rashi's comment on Gittin: that it might be an error, reflective of the opinion of one/some of his teachers, or an attitude that he once had but from which he subsequently deviated. But since Rashi explicitly identifies his interpretation in Beitzah as being his own ("לי נראה"), that one may have the best chance of actually representing what he, personally, believed.
At least, at the time that his commentary on Beitzah was authored.