Pijul is very promising: https://pijul.org/ and https://pijul.org/manual/why_pijul.html
Merging A in B should yield the same result as the opposite with Pijul, etc.