structure merge in git
So I headed out on a search for such tools to plug them into my git. And I was quite impressed by the landscape. Long story short, the problem can be described as the comparison of two Abstract Syntax Trees, and it was shown to have a complexity of O(n*n). Quite complex! And the applied process is usually called structural merge or semantic merge. There are tools trying to do that but they cost a lot to compensate for the complexity of implementation. Though Eclipse has something like that too, but I haven't tried it.
Having looked at this I realised that my problem is too rare and too small to pay so much for it, and too complex to roll my own. But here are some links in case you want to check them out: