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:
- Merging from one source control system to a different one
- GitHub sometimes fails at this task
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.
In the new branch I made the following changes:
- Program.cs – extracted out the StoreRepository class to its own file
- StoreRepository.cs – added this new file
- Store.cs – removed unused references
2 – Install WinMerge
- Go to https://winmerge.org/downloads/?lang=en
- 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.
- Right-click all the files with “Text files are identical”
- Click Hide Items
View the diffs and merge them
- Right-click the file -> Compare
- 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
- Because the files are now the same, it’ll show this prompt. Click OK.
- Ctrl-S to save the merged file
View the new files
- Right-click the file that says “Right only:…”
- 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.