Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinMerge - Is there a way to line up shifted/moved code blocks?

Tags:

winmerge

When using WinMerge I am looking at a file that has had a block of code inserted into a function which causes the rest of the file to be out of sync in the comparison. Mine is much more complex but essentially the same as the simple example below:

  FILE 1                   FILE 2
1 int main() {             int main() {
2
3   int a = 3;               int a = 3;
4   a += 5;                  for(int i = 0; i < a; ++a)
5 }                             a += i;
6                           
7                            a += 5;
8                         }

WinMerge instead of recognizing the for-loop as an inserted block and showing the rest of the file the same it would show differences on line 4,5,6,7,8. I would expect it to sync line 4 of file 1 to line 7 of file 2 and make it a much cleaner diff. Is there a setting for this? I have played with the "Moved Code Block" setting but it simply highlights the matching code block later in the file instead of lining them up.

Any suggestions?

like image 799
jterm Avatar asked Dec 07 '25 21:12

jterm


1 Answers

Try this instead:

  • Select the line on the left file of the merge to match up.
  • Do the same on the right.
  • You now have 2 lines selected concurrently.
  • Menu merge -> Add Synchronization Point (Alt + S)

This will line up those lines on both files.

like image 75
stop journey Avatar answered Dec 13 '25 01:12

stop journey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!