Resolving Merge
Conflicts
Learn how Git detects conflicting changes and how to resolve merge conflicts in text files when collaborating on R projects.
What Is a Merge Conflict?
A merge conflict occurs when Git tries to combine two branches that have made different changes to the same lines of a file. Git cannot decide which change to keep, so it pauses and asks you to resolve the conflict manually.
Why Do Conflicts Happen?
When Conflicts Don't Happen
Git is smart enough to auto-merge when two branches change different lines or different files. Conflicts only arise when the exact same region of a file is edited on both sides.
The Conflict Markers
When Git detects a conflict, it inserts three special markers into the file. Understanding these markers is the key to resolving conflicts.
Anatomy of a Conflict Block
Merge vs Rebase Conflicts
| git merge | git rebase | |
|---|---|---|
| When it happens | Combining two branches | Replaying commits on new base |
| Conflict scope | All conflicts at once | One commit at a time |
| Resolve with | git add & git commit | git rebase --continue |
| Abort with | git merge --abort | git rebase --abort |
| History | Creates a merge commit | Rewrites linear history |
How to Resolve a Conflict
Example 1: Keep One Side
Your R script has a conflict. You want to keep your version (using mean):
Example 2: Combine Both
Sometimes both changes are valuable. Combine them into a single improved version:
Example 3: Multi-line Conflict
Conflicts can span multiple lines. Resolve by carefully reading both versions:
The Complete Workflow
Essential Git Commands
Resolving in RStudio
RStudio's Git pane shows conflicted files with an orange U icon. You can resolve conflicts directly in the editor:
Common Mistakes
Summary: Conflict Resolution
| Marker | Meaning | Action |
|---|---|---|
| <<<<<<< HEAD | Start of your changes | Evaluate your version |
| ======= | Divider between versions | Delete this line |
| >>>>>>> branch | End of incoming changes | Evaluate their version |
| Final file | No markers remain | git add + git commit |
Question 1 of 5
What does the ======= marker represent inside a conflicted file?
Question 2 of 5
After editing a conflicted file and removing all markers, what is the next step?
Question 3 of 5
You are working on an R project. You merge feature-branch into main and see:
CONFLICT (content): Merge conflict in analysis.R
You open analysis.R and want to undo the entire merge, restoring your branch to its state before the merge attempt.
Which command should you use?
Question 4 of 5
When resolving a merge conflict, are you limited to choosing only one of the two versions?
Question 5 of 5
What happens if you commit a file that still contains conflict markers like <<<<<<<?