Repository clean-up

Is there a way to clean a repository without corrupting the Gitlab indexing/references? e.g. there’s a nice doc to perform some repository cleaning on the wiki:

However, if the history is re-written (via the command line or …) how can we update the Gitlab instance so that e.g. references to branches/active merge requests/crosslinks in comments and … are also updated?