Exercise: resolve a merge conflict¶
We have created a public repository that you can use to try resolving a merge conflict yourself. This repository includes some example data and a script that performs some basic data analysis.
First, obtain a local copy (a "clone") of this repository by running:
git clone https://github.com/robmoss/gimlb-simple-merge-example.git
cd gimlb-simple-merge-example
The repository history¶
You can inspect the repository history by running git log
.
Some key details to notice are:
- The first commit created the following files:
README.md
LICENSE
analysis/initial_exploration.R
-
input_data/data.csv
-
The second commit created the following file:
outputs/summary.csv
This commit has been given the tag first_milestone
.
-
From this
first_milestone
tag, two branches were created: -
The
feature/second-data-set
branch adds a second data set and updates the analysis script to inspect both data sets. -
The
feature/calculate-rate-of-change
branch changes which summary statistics are calculated for the original data set. -
The
example-solution
branch merges both feature branches and resolves any merge conflicts. This branch has been given the tagsecond_milestone
.
Your task¶
You will start with the master
branch, which contains the commits up to the first_milestone
tag, and then merge the two feature branches into this branch, resolving any merge conflicts that arise.
You can then compare your results to the example-solution
branch.
-
Obtain a local copy of this repository, by running:
git clone https://github.com/robmoss/gimlb-simple-merge-example.git cd gimlb-simple-merge-example
-
Create local copies of the two feature branches and the example solution, by running:
git checkout feature/second-data-set git checkout feature/calculate-rate-of-change git checkout example-solution
-
Return to the
master
branch, by running:git checkout master
-
Merge the
feature/second-data-set
branch intomaster
, by running:git merge feature/second-data-set
-
Merge the
feature/calculate-rate-of-change
branch intomaster
, by running:git merge feature/calculate-rate-of-change
This will result in a merge conflict, and now you need to decide how to resolve each conflict! Once you have resolved the conflicts, create a commit that records all of your changes (see the previous chapter for an example).
Tip
You may find it helpful to inspect the commits in each of the feature branches to understand how they have changed the files in which the conflicts have occurred.
Self evaluation¶
Once you have created a commit that resolves these conflicts, see how similar or different the contents of your commit are to the corresponding commit in the example-solution
branch (which has been tagged second_milestone
).
You can inspect this commit by running:
git show example-solution
You can compare this commit to your solution by running:
git diff example-solution
How does your resolution compare to this commit?
Note
You may have resolved the conflicts differently to the example-solution
branch, and that's perfectly fine as long as they have the same effect.
Example solution¶
Here we present a recorded terminal session in which we clone this repository and resolve the merge conflict.
Tip
You can use the video timeline (below) to jump to specific moments in this exercise. Remember that you can pause the recording at any point to select and copy any of the text.
Video timeline:
- Start: a quick look around
- Create local copies of branches
- Inspect the
feature/second-data-set
branch - Inspect the
feature/calculate-rate-of-change
branch - Merge the
feature/second-data-set
branch - Merge the
feature/calculate-rate-of-change
branch - Resolve the merge conflicts
- Compare to the example solution