Learning center

Ask another engineer to resolve half of a merge conflict

A conflicted merge cannot be pushed as it stands, so hand over the two commits being merged, the list of conflicted files and the resolutions you are sure of. The receiver recreates the merge. A commit with conflict markers in it records a finished merge and loses the three versions they need.

Why you cannot push the state#

During a conflict, Git keeps three versions of each file in the index: the base, ours and theirs. git ls-files -u lists them:

100644 7fe0854... 1	f
100644 5a90bf0... 2	f
100644 ec7e280... 3	f

A commit has no place for them. In the fixture, git stash refused with f: needs merge. git commit -am wip succeeded, recorded a merge commit with both parents, and stored <<<<<<< lines as the file's content. Whoever checks that commit out has a clean working tree and a merge that Git considers done. Run with Git 2.43.

Show the base version#

Default markers show two sides and hide what each one started from:

  <<<<<<< HEAD
  limit = 20
  =======
  limit = 50
  >>>>>>> x

Both sides changed the value, and the reader cannot see from what. git checkout --conflict=diff3 f rewrites the markers with the base:

  <<<<<<< ours
  limit = 20
  ||||||| base
  limit = 10
  =======
  limit = 50
  >>>>>>> theirs

Now the question is clear: one side doubled the limit and the other made it five times larger. That command recreates the markers, so it discards resolutions already made in the file. Set merge.conflictStyle to diff3 before the next merge to avoid the step.

What to send#

  1. Both commit IDs, from git rev-parse HEAD MERGE_HEAD.
  2. The conflicted files. git merge-tree --write-tree A B lists them without touching a working tree, and exits 1 when there are conflicts. Manual
  3. For each file: resolved, or the question the owner must answer.
  4. Your resolved files, as whole files or a patch against one parent.

The receiver runs git switch --detach A, then git merge --no-commit B, copies the resolved files in, reads them, and stages each one with git add -- PATH. Copying alone is not enough: Git lists a copied file as unmerged until it is staged. After that, git diff --name-only --diff-filter=U lists only the open files.

Frame the open question by behavior#

"Please resolve f" asks the owner to rebuild your context. Give them the two intents and the choice instead:

OursTheirs
Changelimit 10 to 20limit 10 to 50
Commit's stated reasonShort bursts were rejectedA new importer sends 40 rows
If we keep only this oneThe importer failsMemory per request rises

The commit messages supply the second row. git log --merge -p -- f shows the commits on each side that touched a conflicted file.

What a clean merge does not show#

Files that merged without a conflict can still disagree: one side renames a function, and the other adds a call under the old name in another file. Build and test the result, and say in the handoff that you have not done so yet, because you cannot while conflicts are open.

Worked example#

This example is fictional. Ana resolves eleven of twelve files and gives Ben two IDs, a patch with the eleven, and the table above for the twelfth. Ben recreates the merge and picks 50, because the importer's change also capped row size. He finishes in one commit. His build then fails on a renamed helper in a file nobody listed, since it had merged cleanly.

Return to handing over evidence.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading