I accidentally "unflagged" gmail messages with Mail.app, is there a log somewhere so that I can restore them?
GMail keeps no such logs, and neither does Mail.app

Unfortunately, you're kind of stuck searching for the messages yourself.

If you read a lot of text-based mail, and want a "buffer" of sorts to prevent yourself from doing this in the future, a command line mail client like Alpine can be configured to only synchronize changes like message flags/folders on a configured interval, rather than immediately on the remote side.

Homebrew has a package for it: brew install alpine