Bulk edit Gutenberg single images to change from linking to media file to attachment page

Fastest way in my opinion would be to apply filter on the_content with preg_replace_callback to find media URLs and replace them with anything else, like attachment pages. Attachment ID is available as part of <img> class value as well as wp:image attribute in Gutenberg comment. So you just need some smart regexp to match each image block in content and replace it. No undo needed. However this is maybe not the best solution performance wise, as replacents will be done on each page request (unless caching is used).

Better solution would be to run some PHP code once (wp-cli command or otherwise) to loop over all posts and replace post_content value with replaced URLs. Save DB backup before this for undo or create reverse replacement function as well.