The usual way to solve this problem is to bring everything to a common format, then compare the result. That is, given two programs in source language X (for any arbitrary X) and a formatter or pretty-printer for language X, where you don't know if programs P1 and P2 are "the same program" but with different ideas of what a "pretty" layout looks like, we simply run both P1 and P2 through the pretty-printer.
How well this works tends to depend in part on the pretty-printer, since some are more sensitive to initial conditions than others. For instance, some will reflow comments and some won't (or they may have control flags for this).
Note that detecting non-layout-only vs layout-only differences between any two particular snapshots of some program is not really a Git issue, but if you're looking for a way to extract two commits independently, consider these options:
- Use
git worktree
to extract a given commit to a given work-tree.
- Use
git archive
to turn a commit into a tarball or other archive, which you can un-archive anywhere you like.
If you wish to enforce a consistent style, consider a pre-commit hook (see Manuel's comment). Note, however, that writing a good pre-commit hook is pretty hard, because Git builds commits not from what is in a user's work-tree, but rather from what is in Git's index. For some useful tricks, see, e.g., the pre-commit hook here, which is not all perfect, but does at least work for common cases.