I suspect preserving git history is allowed for the purpose of determining copyright compliance.
Also, I doubt you can just keep a copy of all data you ever process, just because it might some day be useful as legal evidence.
But, I was thinking more about companies like Github. If they can hide behind that clause for every single repo they host, the GDPR as a whole becomes useless. Pretty much everything could serve as evidence one day. As far as I know, judges don't like 'hacks' like that.
Also, additionally, code hosting platforms argue they are service providers and should not be liable for copyright infringement as long as they apply notice and takedown.