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:
- Add. We added new lines into the source code;
- Delete. We deleted lines from the source code;
- Change. We changed the content of a line.
- SourceSafe compares the source version against the base version to have a list of changes made in the source version;
- SourceSafe compares the target version against the base version to have a list of changes made in the target version;
- 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:
In the source version, the content is:
In the target version, the content is:
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))
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:
- 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)
||The SQL Server-based Source Control Software Designed to be a SourceSafe Replacement
||The Fastest SourceSafe Remote Access Tool Recommeded by Microsoft
Previous article <<<<: File Diff in SourceSafe / VSS
Next article >>>>: Project Diff in SourceSafe / VSS
SourceSafe How To series home page: VSS / SourceSafe Tutorial