Using Visual SourceSafe - File Merge

This article is a part of SourceSafe / VSS Tutorial

To better understand how files are merged, you first need know something about how diff works. If you have not read the article: Using Visual SourceSafe - File Diff, please click here.

File Merge Introduction

File merge is the foundation of parallel development. Different team members can work on the same file at the same time and merge their changes back when they are done.

SourceSafe supports two work modes, the lock-modify-unlock mode and the copy-modify-merge mode. Lock-modify-unlock is the default mode and in this mode, only one person can work on a file at one time and file merge is avoided in most cases.

How merge is performed

Before discussing how merge is performed in version control, we first need to understand the concept of 3 parties in merge and 3 types of change.

3 parties in merge: To perform a merge, 3 parties are needed: base version, source version and target version.

3 types of change:

  1. Add. We added new lines into the source code;
  2. Delete. We deleted lines from the source code;
  3. Change. We changed the content of a line.

Merge steps:

  1. SourceSafe compares the source version against the base version to have a list of changes made in the source version;
  2. SourceSafe compares the target version against the base version to have a list of changes made in the target version;
  3. SourceSafe tries to apply all the changes in the source version to the target version
    • If there is no conflict, all the changes in the source version are applied to the target version.
    • If there are any conflicts, visual merge is required. SourceSafe shows an interface to let us choose if we want the changes in the source version or the target version. We can also edit the content in the visual merge interface.

How Conflict is Detected If the source version and the target version change the same line of the code, there is a conflict.

Example of merge

For example, the content of the base version is: 1 2 3 4

In the source version, the content is: 0 1 22 3 4

In the target version, the content is: 1 222 3 4 5

So in your current version, you have made the following changes: Added ‘0’ before the first line Changed 2nd line from ‘2’ to ‘22’

In the another version, the following changes have been made: Changed 2nd line from ‘2’ to ‘222’ Add ‘5’ after 4th line.

For the merge result, ‘0’ is added before the first line, ‘5’ is added after the 4th line. But since both of the versions have changed the second line, there is a conflict. When there is a conflict, it is not possible for SourceSafe to merge the files automatically and a visual merge is initiated to let us decide which changes will be kept.

The following is the screen shot for the above scenario:

Screen shot: Visual merge when there are conflict(s) (Screen shot: Visual merge when there are conflict(s))

As we can see that the ‘0’ and ‘5’ are added to the merge result. Since there is a conflict in the second line, the content from the base version, which is ‘2’, is the default content in the merge result. We can choose ‘222’ or ‘22’ for the conflicting line by clicking the mouse on the content we want.

Four scenarios that merge may be performed

In SourceSafe, there are four circumstances when merge may be performed:

  1. Merge branch In SourceSafe, you can branch a file to a different location and change the file content independently. Later on, you can merge the file content in the different locations back when needed.Under this situation:
  • The base version is the version that the file is branched;
  • The source version is the version that you want to merge the changes from;
  • The target version is the version you want to merge the changes into.

To merge a branch:

  • Select a file as the merge target (the merge result will be in this file)
  • Choose menu Versions -> Merge Branches to bring up the Merge Branches dialog box, as shown:

Screen shot: Merge branches (Screen shot: Merge branches)

  • Choose a branch (this is the merge source) in the branch list;
  • Click Merge.
  • Check in when multiple-checkout is enabled. When multiple-checkout is enabled, after we check out a file non-exclusively, someone else can continue to check out and check in the same file.When we check in the file, SourceSafe will check the version number of the file in the VSS database. If the version number in the database is the same as the one we checked out (no one has checked in the file after we checked the file out), a normal check in operation is performed. If the version number in the database is bigger than the one we checked out the file (which means someone else checked in the file after we checked out the file), merge is performed before the normal check in operation.Under this situation:
    • The base version is the version that we checked the file out;
    • The source version is our local version;
    • The target version is the current version in the VSS database.
  • Get a checked out file when multiple checkouts is enabled After we check out a file, when we get the latest version of the file, if someone checked in the file after we checked out the file and if we choose Merge for the Replace writable option in the check out dialog box, a merge operation will be performed.

    Screen shot: Merge option in Get Latest Version (Screen shot: Merge option in Get Latest Version)

    Under this situation:

    • The base version is the version that we checked the file out;
    • The source version is the latest version in the VSS database;
    • The target version is our local copy.
  • Check out a file After we get a file to local disk, if we change the file property to writable, when we check out the file, if we choose Merge for the Replace writable option in the Check out dialog box, a merge operation will be performed.

    Screen shot: Merge option in Check out (Screen shot: Merge option in Check out)

    Under this situation:

    • The base version is the version that we did Get Latest Version;
    • The source version is the latest version in the VSS database;
    • The target version is our local copy.

 

SourceAnywhere - the SQL Server-based SourceSafe Replacement

The SQL Server-based Source Control Software Designed to be a SourceSafe Replacement

SourceAnywhere for VSS - the Fastest SourceSafe Remote Access Tool Recommended by Microsoft

The Fastest SourceSafe Remote Access Tool Recommeded by Microsoft

 

Links: Previous article ««: File Diff in SourceSafe / VSS Next article »»: Project Diff in SourceSafe / VSS SourceSafe How To series home page: VSS / SourceSafe Tutorial

Search Blog Posts