Visually diff two branches using WinMerge

Sometimes you need to diff two branches, and your source control system isn’t the right tool for the job. I’ve ran into this problem in practice in a few different cases:

Whatever the reason for needing to do this, the same general solution can be applied: diff the folders using WinMerge. In this article I’ll be showing you how to use WinMerge to do this task.

1 – Example – Old Branch and New Branch

Here’s a simple example of two branches – named Old Branch and New Branch.

Old Branch

New Branch

In the new branch I made the following changes:

  1. Program.cs – extracted out the StoreRepository class to its own file
  2. StoreRepository.cs – added this new file
  3. Store.cs – removed unused references

2 – Install WinMerge

  1. Go to https://winmerge.org/downloads/?lang=en
  2. Download and install the version that’s right for you

3 – Select the Old Branch and New Branch to diff them

  • Left=Old Branch
  • Right=New Branch
  • Make sure to check Include Subfolders.

4 – Analyze the diffs

Hide the ones with no changes

If you’re dealing with a large number of files, it helps to hide the files with no changes.

  1. Right-click all the files with “Text files are identical”
  2. Click Hide Items

View the diffs and merge them

  1. Right-click the file -> Compare
  2. Use hotkeys to select the diff and copy it to the right
    • Alt-Down = select the next diff
    • Alt-Right = copy the changes from the left to the right
  3. Because the files are now the same, it’ll show this prompt. Click OK.
  4. Ctrl-S to save the merged file

View the new files

  1. Right-click the file that says “Right only:…”
  2. Click Open Right -> with External Editor

This will open the file in Notepad. You can verify the file is what you expected, or make edits if there’s any changes needed.

Leave a Comment