Xdiff identifies fragments of code that have been moved and link them to ease navigation. Xdiff uses a similarity algorithm that identifies fragments of code that have been modified within a user-specified threshold. Even if the code was moved and then changed, Xdiff still detects it as the same block of code.
Xdiff lets you navigate between the fragments and run an independent diff on the moved fragment.
Xmerge can detect code that:
And then merge correctly the code fragment and place it in the moved location.
Check Xmerge in action in the following example:
Suppose you've an initial file. And then two developers start making changes on it in parallel on its own branch: The first developer changes some code, and the second one moves that code.
These changes are made on two different branches:
Now let's merge the changes from the two developers.
The changes done by the first developer are merged automatically.
But let's see what happens when we merge the changes done by the second developer.
Xmerge detects that one of the code fragments that was modified is not there on destination, so the Xmerge button shows up.
When you click on the Xmerge button:
If the selection proposed by Xmerge is ok, you can click on "Xmerge with this selection" and then a "submerge" will merge the refactored code fragment.
Note: in case Xmerge can't detect the moved fragment, it will ask you to find it yourself.
Check the move detection preferences for details.
The Xmerged code fragment will be placed in the right location.
Once the change is checked-in this will be the Branch Explorer: