PricingSign inDownload

Blog / git

Coding agent committed conflict markers

An agent finished a merge with <<<<<<< and >>>>>>> still in the code. Find every leftover marker, the commit that added it, and block it next time.

On this page
  1. What it looks like
  2. Find every leftover marker
  3. The diff3 style adds a fourth marker
  4. Check a branch before you merge it
  5. Find the commit that added them
  6. Fix it
  7. Block it at commit time
  8. Where Joxo fits
  9. Frequently asked questions
  10. How do I find leftover git conflict markers?
  11. Why did git let me commit conflict markers?
  12. How do I stop commits with conflict markers?
  13. How do I find which commit added conflict markers?
  14. What is the ||||||| line in a git conflict?
  15. How do I check an agent's branch for conflict markers before merging?
  16. Try it with your team

An agent resolved a merge conflict, said it was done, and the build now fails on a line like <<<<<<< HEAD. It added the file and committed it without removing the markers. Here is how to find them all, see which commit brought them in, fix it, and stop it happening again. We ran every command with git 2.43 on a scratch repository.

What it looks like#

<<<<<<< HEAD
const title = "Welcome";
=======
const title = "Start";
>>>>>>> other
export default title;

Everything between <<<<<<< and ======= is your side, everything up to >>>>>>> is the branch being merged. Git leaves these for a person (or an agent) to resolve; it doesn't stop you committing them.

Find every leftover marker#

bash
git grep -nE '^(<<<<<<<|=======|>>>>>>>)( |$)'
app.js:1:<<<<<<< HEAD
app.js:3:=======
app.js:5:>>>>>>> other

The pattern only matches markers at the start of a line, followed by a space or the end of the line, so it skips Markdown underlines and long ===== comment rules. No output means there are none.

Git can also check a range of commits for you:

bash
git diff --check HEAD~2
app.js:1: leftover conflict marker
app.js:3: leftover conflict marker
app.js:5: leftover conflict marker

It exits with status 2 when it finds something, which makes it easy to use in scripts. It also reports trailing whitespace.

The diff3 style adds a fourth marker#

If you or the agent set merge.conflictStyle to diff3 or zdiff3, a conflict also shows the common ancestor, after a line of pipes:

<<<<<<< HEAD
x = 3
||||||| 16d3f38
x = 1
=======
x = 2
>>>>>>> o

git diff --check already flags all four lines. For git grep, add the pipes to the pattern:

bash
git grep -nE '^(<<<<<<<|\|\|\|\|\|\|\||=======|>>>>>>>)( |$)'

Check a branch before you merge it#

To check everything an agent's branch adds, compared with where it left main:

bash
git diff --check main...agent/search

The three dots compare against the point where the branch started, so changes made on main since then don't show up. Run it before you approve the agent's pull request; it takes a second and catches markers in files nobody opened in review. It doesn't look at binary files, and a file whose .gitattributes sets a different conflict-marker-size is checked for that length instead.

Find the commit that added them#

The markers usually come in with a merge commit, and git log hides what merges change unless you ask:

bash
git log --oneline -m --first-parent -G '^(<<<<<<<|>>>>>>>)( |$)'
70a630b Remove leftover conflict markers
b372564 Merge branch 'other'

-G lists commits that added or removed matching lines, so the fix shows up too; the oldest one is where they came in. To check a single merge:

bash
git diff --check b372564^1 b372564

Fix it#

Open each file, keep the right version of each block and delete the three marker lines. Then make sure none are left before committing:

bash
git diff --check
git commit -am "Remove leftover conflict markers"

If the merge isn't pushed yet, you can also undo it and redo the conflict yourself (see undo a merge a coding agent made). Read the agent's choice in each block before keeping it: a merge that left markers in may also have kept the wrong side elsewhere.

Block it at commit time#

A two-line pre-commit hook refuses any commit that adds a marker. Save it as .git/hooks/pre-commit:

bash
#!/bin/sh
exec git diff --cached --check
bash
chmod +x .git/hooks/pre-commit

An agent trying to commit a file with markers now gets this and the commit stops:

bad.js:1: leftover conflict marker
bad.js:3: leftover conflict marker
bad.js:5: leftover conflict marker

This hook also rejects trailing whitespace. Hooks only live on your machine, so add the same check to your CI, and tell agents not to skip hooks (see stop a coding agent skipping git hooks). In your project instructions, add: "After resolving a conflict, run git diff --check and fix what it reports before committing."

Where Joxo fits#

Agents fight over conflicts most when two of them edit the same files at once. Joxo shows each agent what a teammate's agent is working on, so they can split the work before it collides; see stop agents editing the same files. Setup is one line pasted into your agent.

Frequently asked questions#

How do I find leftover git conflict markers?#

Run git grep -nE '^(<<<<<<<|=======|>>>>>>>)( |$)' to search the files, or git diff --check <commit> to check the changes since a commit. Both print the file and line of each marker.

Why did git let me commit conflict markers?#

Once a file is added with git add, git treats the conflict as resolved and commits whatever is in it. It doesn't look inside for markers unless a hook runs git diff --check.

How do I stop commits with conflict markers?#

Add a pre-commit hook that runs git diff --cached --check, and run the same check in CI. Commits that add markers are then refused.

How do I find which commit added conflict markers?#

Run git log --oneline -m --first-parent -G '^(<<<<<<<|>>>>>>>)( |$)'. The -m --first-parent part makes git look inside merge commits, where the markers usually come in.

What is the ||||||| line in a git conflict?#

It appears when merge.conflictStyle is diff3 or zdiff3. The lines after it show the code as it was in the common ancestor, before either side changed it, which helps you see what each side meant to do. It is a marker too and has to be deleted with the others.

How do I check an agent's branch for conflict markers before merging?#

Run git diff --check main...<branch>. It checks only what the branch added since it left main and exits with status 2 if it finds a marker or trailing whitespace, so you can also run it in CI on every pull request.