I think that’s already possible using git smudge.
Example here: https://bignerdranch.com/blog/git-smudge-and-clean-filters-m...
Example here: https://bignerdranch.com/blog/git-smudge-and-clean-filters-m...
IMO the next next step is, as others have discussed on HN, getting your version control to store and abstract syntax tree. tree-sitter could make this easier nowadays, but I think it'd need more invasive changes in Git than just using the filters.
See this HN thread https://news.ycombinator.com/item?id=28670372