CH.12 · PART 3

Git pauses.
You decide.

Read both versions, choose the final content, then finish the merge without losing your work.

formal welcomefriendly welcomeYOU choose the final line.

A pause, not a disaster

Two branches edited the same line differently. Git knows both versions, but not which wording you want. It keeps the merge open and asks you to choose. Do not delete the whole file or force the merge.

Read the conflict markers

hello
<<<<<<< HEAD
formal welcome
=======
friendly welcome
>>>>>>> feature/wording

HEAD

The current branch's version, main in this example.

The separator

The equals line separates the alternatives. It is not content to keep.

feature/wording

The version from the branch being merged. You can keep either version, combine them, or write something else.

Try resolving the line

This text exercise checks for marker lines, not whether your chosen wording is correct.

Choose the wording you want and remove the marker lines.

Finish the real merge

Edit each conflicted file. Remove markers, read the resulting code or text, and test it. Staging marks the file as resolved; it does not judge your solution.

git status
# Edit greeting.txt and keep the intended final text.
git add greeting.txt
git status
git commit -m "Resolve greeting conflict"

A clean status after the commit means Git has recorded the merge. Still run the project's tests and inspect the final files.

Real conflict and resolution transcript

Recorded locally on Git 2.34.1. From the Chapter 11 repository, feature/wording committed friendly welcome; main committed formal welcome at the same line. The file was then edited to contain hello and friendly and formal welcome before staging.


$ git switch -c feature/wording 
Switched to a new branch 'feature/wording'

$ git switch main 
Switched to branch 'main'

$ git merge feature/wording 
Auto-merging greeting.txt
CONFLICT (content): Merge conflict in greeting.txt
Automatic merge failed; fix conflicts and then commit the result.

$ cat greeting.txt 
hello
<<<<<<< HEAD
formal welcome
=======
friendly welcome
>>>>>>> feature/wording

$ git status --short 
UU greeting.txt

$ git add greeting.txt 

$ git commit -m Resolve greeting conflict 
[main 7fa9d99] Resolve greeting conflict

$ git status --short 

Need to back out?

git merge --abort attempts to return to the pre-merge state while the merge is still in progress. It can be unable to reconstruct earlier uncommitted work. This is why a clean starting tree matters.

This lesson uses a normal two-branch merge, not a rebase or cherry-pick. Those operations have their own continue and abort commands. Do not copy a recovery command from the wrong operation.

Quick check

Does git add prove the conflict was solved correctly?

No. It tells Git to use the current file as the resolution. You still need to check meaning and tests.

Must you keep only one side?

No. The right result might combine both sides or replace them entirely.

Sources

Official git merge documentation · Git book: Basic Merge Conflicts

Git, Visually · Part 3 · English