Merge Branches allows you to merge the changes made in one branch of a file/folder into another branch. Generally, these two branches are generated from a common original version. After a merge, the changes made based on the original version will be merged into the target branch.
This is a three-way merge. The baseline file is the original version from which the two branches of file are generated. You perform the Merge Branches command on the source version, and the merge result will be in the target branch.
How merge is performed
Before discussing how merge is performed, 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.
In folder branches merge, the version on which Branch was performed is the base version. The modifications made on one branch makes a source version, and modifications made on another branch makes a 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.
- SCM Anywhere compares the source version against the base version to have a list of changes made in the source version;
- SCM Anywherecompares the target version against the base version to have a list of changes made in the target version;
- SCM Anywhere 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. SCM Anywhere 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 one branch, you have made the following changes:
Added "0" before the first line
Changed 2nd line from "2" to "22"
In the another branch, 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 SCM Anywhere 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:
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.