Something that could work with git is to use a map.
Transform:
(a1 a2 (b1 b2))
To: -------------
parent child
-------------
root list1
list1 a1
list1 a2
list1 list2
list2 b1
list2 b2
It should work with diff too if the ids are preserved.