When upon the trial of any proceeding under this chapter it appears from the evidence that the defendant has been guilty of either a forcible entry or a forcible or unlawful detainer, in respect of the premises described in the complaint, and other than the offense charged in the complaint, the judge must order that such complaint be forthwith amended to conform to such proofs; such amendment must be made without any imposition of terms. No continuance shall be permitted on account of such amendment unless the defendant shows to the satisfaction of the court good cause therefor.