Compare and Merge Mechanisms

Visual SourceSafe allows you to compare files or projects. If the items are different, you can reconcile the differences and merge their contents using the merge functionality of Visual SourceSafe. Merging creates a new version in the database.

Comparing Files or Projects

The Visual SourceSafe Tools menu includes a Show Differences command that allows you to compare two files or projects. There is also a Diff button available in the History of File dialog box that invokes the comparison features.

For files, you can customize Show Differences by setting options in the Difference Options dialog box. This dialog box is used to specify the file to compare, the file to compare with it, and the format in which to view the differences. Differences are displayed in the form of lines added, deleted, or changed. For the display, you can choose the standard SourceSafe format, which gives a text display; a visual format, which uses the merge window to show differences in selectable colors; or a standard UNIX format.

Note

For binary files, Visual SourceSafe identifies differences, but cannot display them.

The Show Differences command for Visual SourceSafe projects allows you to compare two projects, a project and a Windows folder, or two Windows folders. For comparing two projects, use the Project Difference dialog box to set options for Show Differences. Before the lists of files that represent the differences are displayed, Visual SourceSafe displays a command dialog box that allows you to filter the file list so that you can limit reporting to the files that interest you.

Merging Files

In Visual SourceSafe, merging is only necessary when you are sharing files in a multiple checkout mode. Merging is required when you choose the following commands on the Versions menu:

  • Check In

  • Get Latest Version

  • Merge Branches

Visual SourceSafe supports two merge types: visual merge (default) and manual merge. You can select a merge type from the General tab of the SourceSafe Options dialog box. For more information about the visual merge type, see the section "Visual Merge Mechanism" later in this document. For information about the manual merge type, see the section "Manual Merge Mechanism."

By default, Visual SourceSafe deletes a file if it finds no merge conflicts. If it detects conflicts, however, it renames the original file with the extension .org. Renaming the file ensures that you always have a copy of the original file. The Backup_Ext initialization variable determines the file name.

By default, Visual SourceSafe also creates a temporary merge file. This file has the extension .mrg and is always deleted after the merge process is completed. The file name extension is controlled by the Merge_Ext initialization variable.

After you complete a merge, Visual SourceSafe observes the following rules:

  • If there are merge conflicts, it keeps the file checked out. You must resolve the conflicts to check in the new file. For more information, see the section "Merge on Check-in" later in this document.

  • For a Merge Branches operation, it keeps the file checked out if you are merging a file into a project where you already have it checked out.

  • For all other circumstances, it gives you the option of checking the file in automatically after the merge or leaving the file checked out to your working folder.

Visual Merge Mechanism

A visual merge, which is recommended, presents a visual merge window in which you can resolve all file differences quickly and with maximum control. The top two panes of the visual merge window represent the two files that you are merging. The file on the left is the database copy, and the one on the right is your local copy. If you are using the visual merge window for the merging of branches, you will see two versions of a branched file from different projects. The top two panes cannot be edited, but you can cut or copy from the top two panes and paste into the lower pane of the visual merge window.

The lower pane of the visual merge window represents the merge results for the two files, and can be edited. The display starts with all non-conflicting changes already made to create a new merged version of the file. Then it changes dynamically as you use the other two panes to select the changes to place in the merged file. If you are merging branches, the lower pane contains the original file from just before you created the branch.

All three panes of the visual merge window attempt to scroll together vertically, although they sometimes lose synchronization. The upper panes also scroll together horizontally. The horizontal positioning of the lower pane is independent.

The colors and font used in the visual merge window are controlled by the difference options that you set. Font style, for example, bold or italic, cannot be changed.

Manual Merge Mechanism

For those who have worked with earlier Visual SourceSafe versions, or for batch files or scripts that must run without user intervention, you can choose the manual merge type for merging file versions. This type of merge places identifying markers (six consecutive equal signs) in your file. In any text editor, you can search for and edit them manually.

The following is an example of what the Visual SourceSafe conflict markers might look like when you use manual merging:

<<<<<< SourceSafe version
if (a <= 5)
|||||| Original version
if (a < 5)
======
if (a < 6)
>>>>>> Local version

Visual SourceSafe displays the original version of a file between the database and local versions. This can be helpful to you in determining how best to clean up a file during manual merging. You must remove all change markers before checking a merged file.

Merge on Check-in

This type of merge combines changes when you are sharing a file and must check it in. If there are conflicts between two files that are checked out in multiple checkout mode, Visual SourceSafe keeps the file checked out. You must resolve the conflicts for Visual SourceSafe to allow you to check in the file.

Most cases of merging on check-in require a two-way merge. For this merge technique, you and others have changed different sections of a file and Visual SourceSafe just combines all the changes into the master copy of the file.

However, if Visual SourceSafe detects that two of you have both modified the same piece of a file, a three-way merge technique must be used. The merge mechanism alerts you to resolve file conflicts before you proceed with a database operation. If manual merging has been selected, you must edit the local copy of the file to resolve differences between the local copy and the other file version. If visual merging has been selected, Visual SourceSafe opens the merge window in which you can see the file differences. You can point and click on a line-by-line basis to tell the merge mechanism what the final file should contain.

Merge on Get Latest Version

In a multiple checkout situation, you can set merging to occur between your local copy of a file and the database version. To enable merging in this case, use the Local Files tab in the SourceSafe Options dialog box. For Replace writable files, choose Merge.

Merge Branches

Visual SourceSafe allows you to merge branched copies of a file by using the Merge Branches option on the Versions menu. For more information, see How to: Merge File Versions.

Command Line Merge

You can perform merge operations from the command line using the Merge command. For more information, see Merge (Command Line).

Visual SourceSafe also allows merge operations through the SSEXP utility. For more information, see SSEXP Utility.

See Also

Tasks

How to: Merge File Versions

Reference

Backup_Ext Initialization Variable
Difference Options Dialog Box (Explorer and Plug-in)
Merge (Command Line)
Merge_Ext Initialization Variable
Project Difference Dialog Box (Explorer and Plug-in)
SourceSafe Options Dialog Box, General Tab
SourceSafe Options Dialog Box, Local Files Tab (Explorer and Plug-in)
SSEXP Utility