Roll back rewritten refs if rewriting fails