This is a curated set of merge conflicts from various open-source git repositories for conflict resolution practice. This repository includes the git commits from several open-source projects. None are merged into the master branch, but you can access the code and reproduce each conflict by cloning this repository and using the git commands given in the examples below.
When resolving conflicts in git, it's recommended to use diff3. See the blog post Take the pain out of git conflict resolution: use diff3.
After cloning this repository,
-
Ensure your working directory is clean.
git reset --hard; git clean -df -
Check out first parent (
^1) of the merge commit. This is the commit that was checked out when the merge originally happened.git checkout <merge_commit>^1 -
Merge the commit that was originally merged, the second parent (
^2).git merge <merge_commit>^2 -
Resolve the conflict, and commit the result.
-
Compare your result to the original merge result to yours (differences in your resolution are prefixed with
+). Keep in mind that the author may not have resolved the conflict correctly.git diff <merge_commit>
Enable diff3
git config --global conflictstyle.diff3
View the left side of the merge, what was checked out (HEAD / ours, always the top conflict section):
git diff <merge_commit>^2...<merge_commit>^1 [file_paths...]
View the right side of the merge, what was merged (MERGE_HEAD / theirs, always the bottom conflict section):
git diff <merge_commit>^1...<merge_commit>^2 [file_paths...]
Reproduce this conflict:
git reset --hard; git clean -df
git checkout rails.a^1
git merge rails.a^2
Commit, then check your work:
git diff rails.a
Reproduce this conflict:
git reset --hard; git clean -df
git checkout pry.a^1
git merge pry.a^2
Commit, then check your work:
git diff pry.a
Reproduce this conflict:
git reset --hard; git clean -df
git checkout pry.e^1
git merge pry.e^2
Commit, then check your work:
git diff pry.e
Since both branches approached solving the same problem in different ways, it's up to you as the merger to decide which to choose. Your solution may vary from the original merger's.
Reproduce this conflict:
git reset --hard; git clean -df
git checkout pry.b^1
git merge pry.b^2
Commit, then check your work:
git diff pry.b
Reproduce this conflict:
git reset --hard; git clean -df
git checkout guard.a^1
git merge guard.a^2
Commit, then check your work:
git diff guard.a
Note: "deleted by us" in git status refers not to authorship but rather which parent deleted.
- Ours / by us = 1st parent (
^1) - Theirs / by them = 2nd parent (
^2)
Reproduce this conflict:
git reset --hard; git clean -df
git checkout docker-sync.a^1
git merge docker-sync.a^2
Commit, then check your work:
git diff docker-sync.a
You'll likely come up with a different resolution, but both could be considered correct!
There's also a semantic conflict resolved in the official resolution.
Reproduce this conflict:
git reset --hard; git clean -df
git checkout pry.d^1
git merge pry.d^2
Commit, then check your work:
git diff pry.d
External repository: doximity
Be sure to first commit or stash any work in progress!
Reproduce this conflict:
git reset --hard
git checkout 1e4e700cbee^1
git merge 1e4e700cbee^2
Commit, then check your work:
git diff 1e4e700cbee
Check out the branch you were on previously:
git checkout -
Reproduce this conflict:
git reset --hard; git clean -df
git checkout pry.c^1
git merge pry.c^2
Commit, then compare your solution with the original merge commit:
git diff pry.c
Check your work against my corrected solution:
git diff pry.c.corrected
Reproduce this conflict:
git reset --hard; git clean -df
git checkout expertiza.c^1
git merge expertiza.c^2
For this exercise, focus only on the conflicting .erb files.
Reproduce this conflict:
git reset --hard; git clean -df
git checkout rails.b^1
git merge rails.b^2
Commit, then compare your solution with the original merge commit:
git diff rails.b
Check your work against my corrected solution:
git diff rails.b.corrected
Reproduce this conflict:
git reset --hard; git clean -df
git checkout guard.b^1
git merge guard.b^2
Commit, then check your work:
git diff guard.b
Reproduce this conflict:
git reset --hard; git clean -df
git checkout expertiza.b^1
git merge expertiza.b^2