formatting and rewriting, upto HEAD