This topic describes how to use the WinMerge File Compare window to compare and merge text files. To understand the basic concepts about differences discussed here, we suggest you read Overview of file comparing and merging first. See Overview of file comparing and merging for related information about hex files.
You can start a file compare operation from either the WinMerge window or a Command Prompt window.
- From the WinMerge window
- From a Command Prompt window
The File Compare window displays compared files in two File panes, side by side. The WinMerge toolbar and context menu provides functions for viewing, navigating, and merging differences. The screen shot below shows a comparison of two versions of a file.
The left and right File panes show the text contents and differences of the two files being compared. The File panes are the main area for navigating and merging differences, and also allow you to edit the text directly. This section describes the features that support these actions, and ways that you can customize the File panes.
The header at the top of each File pane shows the full path of the source file. The left and right file names are also identified in the header of the Compare Window, above the File panes.
One of the File panes is always active (indicated by the dark header background); the other is inactive and has a lighter header bar. You can edit only in the active pane (as described in File pane editing features). Click in either side to make it active and make the other side inactive.
An asterisk (*) before the filename in the header indicates that there are unsaved changes in the file.
The header bar's context menu has shortcuts that are useful for copying and pasting file information:
WinMerge highlights several types of differences in the File panes. The Colors page in the Options dialog defines a set of background and text colors for most difference types, with variations indicating their state: unselected, selected, or deleted. This section describes how each of the basic difference types is detected and displayed.
Sometimes it's useful to highlight not just difference blocks, but also the text within them that is changed. You can disable or enable them in two ways:
View line differencesoptions in the Options dialog Editor page.
Click View → View line differences to toggle line differences on or off.
Remember that WinMerge navigation and merging functions (like Next Difference or Copy Left) work on difference blocks, not on line differences within them.
This section describes how line differences are detected and marked. Note that the effect of these options is also affected by your current whitespace settings in the Options dialog Compare page.
Although WinMerge is a not a full-featured editor or IDE, it does provide basic editing functions, like Undo and Redo, Find and Replace, and Goto. These basic editing tasks are often needed during merging (for example, to change text within differences). You can edit in the active File pane (remember, click in a pane to make it active). Changes are not written to a file until you save a pane to a result file.
WinMerge editing features also include syntax highlighting. This optional feature supports several file formats, and you can configure the colors used. Note that syntax highlighting is not applied within differences, as the preceding screen shot shows.
Make sure that Automatic rescan is enabled, as described in Rescanning files. If it is not, manually refresh your view (press F5) before and after editing a file, to ensure that WinMerge difference detection is up to date.
You can choose fonts for the File pane by clicking View → Select Font. WinMerge supports only fixed width fonts.
Here are font suggestions for using WinMerge with East Asian languages:
- Simplified Chinese: SimSun or SimHei fixed-width fonts
- Traditional Chinese: MingLiU fixed-width font
- Japanese: MS Gothic or MS Mincho fixed-width fonts
- Korean: GulimChe fixed-width font (not Gulim, because this variant uses proportional-spacing glyphs that are not centered in grid cells and poorly aligned in fixed-width mode).
The File panes have optional gray margins that show line numbers and some symbols. To show or hide the margins, clicking View → View Margins. If you are using multiple File Compare windows, you can control margins for each window independently. The margin can show any or all of these features:
Line numbers, if View → View Line Numbers is enabled.
Bookmarks, if Edit → Bookmarks is enabled. A bookmark is a blue circle, in the margin next to a line, that you can make WinMerge remember and return to.
To set a bookmark on a line, double-click in its margin (or press (Ctrl+F2). The same action deletes an existing bookmark.
To navigate bookmarks, click Edit → Bookmarks and choose Next or Previous.
Double-click a single bookmark to delete it (or press (Ctrl+F2).
Click Edit → Bookmarks → Clear All Bookmarks to delete all bookmarks.
Word wrap arrow symbols, if View → Wrap Lines is enabled.
The following screen shot shows a margin with bookmarks and word wrap enabled. Without line numbers, the margin width is minimal.
The next screen shot shows a margin with bookmarks and line numbers enabled. Notice that the margin is wider. In fact, the margin is wide enough for the largest line number. Thus, the margins for large files with many lines can be quite wide.
The WinMerge toolbar and menus provide a range of functions to navigate, select, and merge differences within files.
WinMerge shortcuts have the same names and buttons whether you open a Folder Compare or File Compare window. However, the functions behave differently: with a File Compare window, the functions operate on differences within files, not on differences within folders.
The difference functions you can use depend on your context, which often changes as you work. This means that a function is available only when its operation is possible for a given location or other condition in your WinMerge environment. For example, if you click in a line of text within a difference, you might notice several navigation and merge buttons become enabled in the toolbar. If you click in another area of text that is not within a difference, these functions become unavailable.
Difference functions are available in the WinMerge toolbar,and also through these alternate mechanisms:
WinMerge menus, especially Merge
Context menus within the File Compare window (when you right-click in text)
Difference functions are described in Navigating differences and Merging differences, later in this topic. Quick start and Overview of file comparing and merging provide examples of comparing and merging.
File → Merge Mode restores these WinMerge 1.7.1 single keyboard shortcuts for difference merging and navigating functions:
- Up and Down keys for the
- Left and Right keys for
Merge mode omits the Alt key for these common operations (making them quicker to use than the normal mode). Note that the Shift and Alt Arrow key combinations work in merge mode in the same way as normal mode.
Merge mode is indicated in the status bar by the text, Merge.
The Location pane, to the left of the File panes, maps the entire length of the compared files into two vertical bars (corresponding to the left and right File panes). It is especially useful for working with files that are too long to easily navigate in the File panes.
The Location pane shows several kinds of items:
Goto Line 1: Moves the cursor to the top of the file.
Goto: Moves the cursor to a line you specify (described in Navigation functions).
No Moved Blocks: Turns off moved difference color for moved blocks.
All Moved Blocks: Turns on moved difference color for all moved blocks.
Moved Block for Current Diff: Turns on moved difference color only for current selected moved difference.
The Diff pane shows the contents of the two sides of a selected difference.
When you select a difference, the two versions are loaded in the upper and lower sides of the Diff pane. In this way, the Diff pane confirms which lines are included in a difference, and lets you examine them in isolation from the rest of the file.
You can merge differences directly in the Diff pane by
right-clicking in either the top or bottom side and choosing
Copy to Right or
Copy to Left.
Each File pane contains a status bar at the bottom. The status bar contains several panes with different types of information about the document and your location in it:
- Line status
- Read-only status
- File encoding
- EOL style
When a File Compare window is open, the WinMerge window status bar shows one of these messages about the compared files:
Identical: The files contain no differences
nDifferences Found: The number of differences detected, displayed only when no difference is selected.
n: The selected difference's sequence number in the total number of differences, starting with 1.
By default, the WinMerge window displays a single File Compare window. If you start another file comparison (by clicking File → Open and selecting another pair of files) while a File Compare window is currently open, the current File Compare window is closed, unless WinMerge detects unsaved changes in the left or right file. If you have modified either file, WinMerge prompts you to save or discard your changes before opening a new File Compare window.
For example, in the next screen shot WinMerge gives you a chance to save changes detected in the right side file:
If you plan to work with multiple compare operations simultaneously, consider setting (checking) the Enable multiple compare windows for File compare option, which is disabled by default. With this option enabled, you can open multiple File Compare windows without the intervening Save step.
By default, Compare windows are displayed as individually resizeable child windows within the WinMerge window, like this:
If you maximize your Compare window (by clicking its Maximixe button), the window fills all the available space in the WinMerge window, giving you the most room possible to work in. However, if you are working with multiple Compare windows, only one one maximized window is visible: any others are hidden. The screen shot below shows the header area of a maximized Compare window:
To access other Compare windows, you could return to the default view by clicking the Restore button. But a better solution is to enable tabs by setting (checking) View → Tab Bar.
When you display the Tab bar, each Compare window has a tab that shows the filenames of the two compared files. Now, you can easily identify the available Compare windows. To open any of them, just click its tab:
This section describes how to navigate and select differences in the File Compare window. Note that when you select a difference, it is always selected in both File panes.
To save time, enable Automatically scroll to first difference in the General page of WinMerge options. Then you don't have to manually navigate to the first difference and select it.
Here are the functions for navigating differences in the File Compare window, and their shortcuts in the toolbar and menus:
Merging copies differences from one File pane to the other: either left to right, or right to left. This is different from directly editing text using WinMerge's editing functions (described earlier in this topic).
By default, the Automatic rescan option is enabled in the Editor page of WinMerge options. Rescanning keeps your your compare and merge operations up to date. Without rescanning, WinMerge differences does not detect changes that might occur to files while you are comparing them, for example in an external editor.
Rescanning occurs when you perform certain actions (like merging a difference or editing a file) during a file compare. If a file has changed, WinMerge displays a dialog advising you that another application has updated the file, and asks whether you want to reload the file.
Click Yes to reload the file before proceeding, or No to ignore the changes and work with the earlier loaded version of the file.
If Automatic rescan is disabled, or if you suspect that a file might have changed, we strongly advise that you run Refresh before performing any merge operation: click Edit → Refresh or the toolbar button, or press F5.
If a merge result looks incorrect, click Edit → Undo or press Ctrl+Z to undo the merge. Then rescan the files and try merging again.
The merging functions can implicitly select differences based on a cursor location or text selection. For example, if you click anywhere in a difference and then click the Copy Right toolbar button, the entire difference block is merged. This makes it easy to merge many small differences. Similarly, if you select text that spans all or part of multiple differences, all the included differences are merged with a single merge command.
If the result of a merge operation is not what you expected, you can click Undo to reverse the operation.
Here are the merge functions and their shortcuts in the toolbar and menus:
You can use WinMerge to resolve conflict files that some version control systems produce during their merge operations. A conflict file is created when a merge encounters differences that cannot be automatically resolved. It is a single file containing the incompletely merged content of the two files. WinMerge separates the conflict file into separate files and opens those files in file Compare window. You can then use WinMerge's compare and merge functions to resolve the conflicts and save the merged result file.
Click File → Open Conflict File, and use the Open dialog to select the conflict file in your file system. The conflict file opens in the File Compare window:
The left File pane file header is titled, Theirs File. This side represents the file that is usually in the version control system's repository. This file usually cannot be edited, so WinMerge sets the left File pane to be read-only. This means that differences can be merged only from this file to the other file.
The right File pane is titled, Mine File. This side is the working copy of the file. All changes should be done to this file, which is the result file.
The Mine File side is set to modified after opening conflict file (you will notice the asterisk in the File pane header). This allows you to save the file quickly if the it does not require any changes. It also ensures that you do not forget to resolve the files. If you choose not to save the file, the original conflict file is not modified.
Use all the normal compare and merge functions described earlier in this topic to resolve the conflicts in the Mine File pane.
When you are done, click Ctrl+S to save the Mine File side as the result file. By default, the new version overwrites the original conflict file. Alternatively, you can click File → Save Right → Save As, and choose a different file name.
Many version control systems allow you to configure an external merge tool. If yours does, you might be able to have your version control system launch WinMerge automatically when a merge conflict occurs.
You can also open a conflict file from the WinMerge command line,
which accepts three filename parameters:
Mine, and optionally,
Resolved (if you
want a different result file from the conflict file). For more
information, see Command line. Single path to the
conflict file is also accepted in command line.