If your repo ends up in a weird state, learn how to fix it. It should not be terribly complicated, especially if there is no rebasing happening.
Keeping a "bar copy(2) final working.py" file is not about having a nice looking timeline, it makes it very easy to get back to a working state. All you need is copy and paste, or keep the working function as a comment in bar.py. You can see your working code and know you're not messing with it when you're experimenting with bar.py. I'm not saying that's the best way of doing it, but it's a very common use case that's not usually addressed in git guides, where it's all about pushing commit after commit, maybe branching, maybe pushing to a remote with others, but rarely enough focus on undoing mistakes after some experimenting if you didn't branch first.
You are operating under the assumption that foo() changes in a vacuum. That is an invalid assumption for lots of software changes.
Commits are supposed to contain one logical change each. That logical change may or may not cross function boundaries (often it will).
Reverting a commit should revert the logical change. That is how you accomplish what you're after in git.
And plenty of times functions are self contained enough that you can change the function body without changing other code as well.