Lesson 02 of 05Concept

Reading Conflict Markers

Goal: Read a conflicted file and know exactly what to change to resolve it.

Both versions, side by side

When a merge conflicts, Git writes both versions of the disputed lines into the file, fenced by three kinds of marker lines. Everything outside the markers merged cleanly.

src/auth.ts after a conflicting merge

export const provider = "password";
// Session settings
<<<<<<< HEAD
export const timeout = 15;
=======
export const timeout = 60;
>>>>>>> feature/login
export const rememberMe = true;

The three markers

- <<<<<<< HEAD starts the conflict. The lines below it are your current branch's version. - ======= separates the two versions. - >>>>>>> feature/login ends the conflict. The lines above it are the incoming branch's version.

Resolving means editing

Decide what the code should say, then make the file say exactly that:

  • keep your version, keep theirs, or write a combination of both;
  • delete every marker line;
  • save the file.

There is no special command for this part. It is ordinary editing.

One possible resolution

export const provider = "password";
// Session settings
export const timeout = 60;
export const rememberMe = true;
The team agreed on 60 minutes. The markers and the 15-minute version are gone.

Telling Git it is resolved

$ git add src/auth.ts

Staging a conflicted file marks it as resolved. Once every conflicted file is staged, git commit creates the merge commit and the merge is complete.

Where you are, at any time

$ git status

On branch main
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/auth.ts

Finished reading?

Marking it complete records your progress and XP for this lesson.