Skip to main content

GitKit (Linux Desktop Edition): Learn git and GitHub in Context

Section 5.1 Understanding Merge Conflicts

The exercises in this section provide practice in identifying merge conflicts and their resolutions.

Exercises

Figure 5.1.1 shows the main branch in the right panel, the contributor’s feature branch in the left panel, and the common ancestor in the middle.
Three panels of code (feature branch, common ancestor, main branch)
Figure 5.1.1. Example merge conflicts with Best Common Ancestor.

1.

Consider the merge shown in Figure 5.1.1. As shown in the right-hand panel, the maintainers have merged commits into the main branch that fix several bugs that existed in the program. The left-hand panel shows a contributor’s feature branch with has been changed to use more descriptive variable names but that has not fixed the bugs. The center panel shows the best common ancestor of the feature and main branches.
(a)
Study the program in the main branch and then describe in a sentence the computation that the program is trying to perform. Note: The Feature Branch and the Best Common Ancestor both contain bugs.
(b)
Hint.
Merge conflicts occur when both source branches change the same line.
(c)
Hint.
Merge conflicts occur when both source branches change the same line.
(d)
Would the feature branch in Figure 5.1.1 be able to be merged automatically by the project maintainers? Briefly explain your answer.
(e)
Figure 5.1.2 shows the main branch in the right panel, the contributor’s feature branch in the left panel, and the common ancestor in the middle.
Three panels of code (feature branch, common ancestor, main branch)
Figure 5.1.2. Example merge conflicts with Best Common Ancestor.

2.

Now consider the merge shown in Figure 5.1.2. As shown in the right-hand panel, the maintainers have merged commits into the main branch that fix several bugs that existed in the program. The left-hand panel shows a contributor’s feature branch with has been changed to use more descriptive variable names but that has not fixed the bugs. The center panel shows the best common ancestor of the feature and main branches.
(a)
Study the program in the main branch and then describe in a sentence the computation that the program is trying to perform. Note: The ** indicates exponentiation (e.g. x**2 is x squared). Note: The Common Ancestor contains a bug that is fixed in different ways by the main branch and the feature branch.
(b)
Hint.
Merge conflicts occur when the feature, main, and common ancestor branches are all different.
(c)
Hint.
Merge conflicts occur when the feature, main, and common ancestor branches are all different.
(d)
Would the feature branch in Figure 5.1.2 be able to be merged automatically by the project maintainers? Briefly explain your answer.
(e)
(f)
Look carefully at your result in Task 5.1.2.e. Will the resulting program perform the computation correctly? Briefly explain why or why not.
(g)
When a merge can be completed automatically, does it guarantee that the Merged Result will be correct?.
You have attempted of activities on this page.