Sub topic 4
Reading Conflict Markers in Metadata XML
This chapter shows how to read the text Git writes into a Salesforce metadata file when a merge stops. You will learn what each marker means and how to tell which branch contributed which lines. You will also learn why a file with markers is no longer valid XML, and which conflicts leave no markers at all.
What this chapter assumes
- You can create branches, commit, and run
git mergeorgit pull. - You work in a Salesforce DX project in source format, under
force-app. - You know basic XML: elements, nesting, and closing tags.
- You can run
sfcommands against a sandbox or scratch org.
Finding the files that need attention
When a merge stops, Git has already merged every file it could. It leaves only the conflicted files for you. Start by listing them.
git merge feature/new-field
# Auto-merging force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xml
# CONFLICT (content): Merge conflict in force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xml
# Automatic merge failed; fix conflicts and then commit the result.
git status
git diff --name-only --diff-filter=UThe last command prints only unmerged paths. git status also lists them, under "Unmerged paths". Open each listed file and search for the marker lines.
Anatomy of a conflict block
Git inserts three kinds of marker lines. Each marker starts in column 0 and is exactly seven characters long.
| Marker | Meaning |
|---|---|
| `<<<<<<< HEAD` | Start of the conflict. The lines that follow come from your current branch. |
| `=======` | Divider between the two versions. |
| `>>>>>>> feature/new-field` | End of the conflict. The lines above it come from the branch being merged in. |
Everything outside these markers merged cleanly and is the same on both sides, or was changed on only one side. Only the text between <<<<<<< and >>>>>>> needs a decision.
A worked example
Two developers each added a field permission to the same permission set, at the same position in the file. This is what the file looks like after git merge feature/new-field:
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<fieldPermissions>
<editable>true</editable>
<field>Account.Region__c</field>
<readable>true</readable>
</fieldPermissions>
<<<<<<< HEAD
<fieldPermissions>
<editable>false</editable>
<field>Account.Tier__c</field>
<readable>true</readable>
</fieldPermissions>
=======
<fieldPermissions>
<editable>true</editable>
<field>Account.Segment__c</field>
<readable>true</readable>
</fieldPermissions>
>>>>>>> feature/new-field
<label>Sales Access</label>
</PermissionSet>Read it in four steps:
- The
Account.Region__cblock above the markers is shared. Nothing to decide there. - Between
<<<<<<< HEADand=======is your side. It addsAccount.Tier__cwith read-only access. - Between
=======and>>>>>>> feature/new-fieldis the incoming side. It addsAccount.Segment__cwith edit access. - The
<label>line below the markers is also shared.
The two sides touch different fields, so the changes are independent. Git cannot know that, because it merges lines, not Salesforce meaning. It saw two different insertions at one spot and stopped. The next chapters cover how to resolve this case. For now, the skill is recognizing it.
Which side is "ours"?
The label after <<<<<<< depends on the operation you ran.
git merge:HEADis the branch you are on. The label after>>>>>>>is the branch you merged in.git rebase: The sides are reversed.HEADis the branch you are rebasing onto, such asmain. The label after>>>>>>>is the commit you are replaying, which is your own work.git stash pop: The labels readUpdated upstreamandStashed changes.
This matters when you choose a side. git checkout --ours and --theirs follow the same reversal during a rebase, which is a common source of mistakes.
Why markers break the XML
A file with markers is not well-formed XML. The parser sees <<<<<<< HEAD as the start of a tag and fails. The failure shows up in other tools too:
xmllintreports a parse error.sf project deploy startfails with a parsing error for that file.- If you commit the file by mistake, the broken file is now in your history and reaches your teammates.
Git does not check that you removed the markers. git add on a file that still has them marks it as resolved without complaint. You have to check yourself. This command lists any marker that remains:
grep -rnE '^(<<<<<<<|=======|>>>>>>>)' force-appThe ^ anchor limits the search to lines that start with the marker. That avoids false matches on text that merely contains equals signs.
Seeing the common ancestor with diff3
By default, markers show only two versions. You cannot tell whether a line was changed by one side or deleted by the other. Git can add a third section, the common ancestor, which is the version both branches started from.
git config merge.conflictStyle zdiff3
git checkout --conflict=diff3 -- force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xmlzdiff3 needs Git 2.35 or later. Use diff3 on older versions. The second command rewrites the file with the new style. It discards any edits you already made to that file, so run it before you start editing. A block now has four parts:
<<<<<<< HEAD
<editable>false</editable>
||||||| parent of the merged commit
<editable>true</editable>
=======
<editable>true</editable>
>>>>>>> feature/new-fieldThe ||||||| section shows the original value. In this example, the original was true. Your branch changed it to false, and the incoming branch kept true. Only your side changed the value, so the sensible result is false. With the ancestor visible, this is clear. With two-way markers, it looks like a coin toss.
The exact text after ||||||| varies by Git version and operation. Do not match on it in scripts.
Edge cases that confuse readers
Conflicts that do not line up with elements
Git compares lines. It does not know XML structure. A conflict block can therefore begin or end in the middle of an element, especially when both sides add similar blocks, since repeated lines such as </fieldPermissions> and <readable>true</readable> can be matched to the wrong block.
<fieldPermissions>
<editable>true</editable>
<field>Account.Region__c</field>
<<<<<<< HEAD
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Account.Tier__c</field>
=======
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>true</editable>
<field>Account.Segment__c</field>
>>>>>>> feature/new-field
<readable>true</readable>
</fieldPermissions>Here, the shared closing lines sit outside the block, so each side looks incomplete. Do not edit line by line. Count opening and closing tags for the whole region, and rebuild complete elements.
Several conflict blocks in one file
Large files such as profiles often contain many blocks. Resolve every one. After each edit, run the grep check, because a missed block in the middle of a 3,000-line file is easy to overlook.
Conflicts with no markers
Git writes markers only for content conflicts. Other conflicts are reported in the merge output and git status, but the file contains no markers:
- Modify/delete: One branch changed a file and the other deleted it. For example, someone deleted a custom field while you edited a permission set that is stored in a different file. The file is either kept in its modified form or absent, and Git waits for you to choose.
- Rename conflicts: Both branches moved the same file to different paths.
- Binary or static resource files: Git cannot show markers inside binary content. Static resources such as ZIP files are an example.
For these, git status is the source of truth. Do not rely on searching for markers.
Line endings and whitespace
If one developer's editor converted line endings or re-indented the file, almost every line can differ. The result is one conflict block covering the whole file. When a block looks huge for a small change, compare the two sides with git diff --ignore-all-space before you decide anything.
What to do next
Reading is the first step. Once you can say what each side added, removed, or changed, you can choose between keeping both sides, picking one, or re-retrieving from an org. The following chapters cover these in turn.
Exercise
You run git rebase main on your feature branch and hit a conflict in a profile. The block shows <<<<<<< HEAD with a field permission for Account.Tier__c, and >>>>>>> a1b2c3d (Add Segment field) with a permission for Account.Segment__c. Which side is your own work? After resolving, which command finds any markers you missed?
Show answer
The Account.Segment__c side is your work. During a rebase, HEAD is the branch you are rebasing onto (main), and the label after >>>>>>> is the commit being replayed from your branch. To find leftover markers, run grep -rnE '^(<<<<<<<|=======|>>>>>>>)' force-app.