Sub topic 4
Reading conflict markers in metadata XML
This chapter assumes you can use Git branches, commits and merges, you know the layout of a Salesforce DX project, and you can read basic XML. You will learn to read the markers Git writes into a conflicted metadata file and to tell what each side changed.
What Git writes into the file
When Git cannot combine two changes on its own, it stops the merge and edits the file in your working directory. It wraps each conflicting region in three marker lines. Everything outside the markers merged cleanly and needs no action.
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 lists only the files that still have unresolved conflicts. Use it as your to-do list.
The three markers
| Marker | Meaning |
|---|---|
| `<<<<<<< HEAD` | Start of the conflict. The lines below it come from your current branch (the one you ran `git merge` on). |
| `=======` | Divider between the two versions. |
| `>>>>>>> feature/new-field` | End of the conflict. The lines above it come from the branch you are merging in, named after the marker. |
Each marker sits at the start of its own line. That detail matters later, when you search for leftovers.
A conflict in a permission set
Here is the conflicted file from the merge above.
<?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 three steps:
- Find the context outside the markers. The
Account.Region__cblock and the<label>line are unchanged, so they show where the conflict sits in the file. - Read the top half. Your branch added a
fieldPermissionsblock forAccount.Tier__c. - Read the bottom half. The incoming branch added a block for
Account.Segment__c.
The two halves touch different fields. Git still reports a conflict because both branches inserted text at the same position, and it cannot decide the order. That is the usual cause in metadata files, which keep their elements in sorted order, so many changes land in the same spot.
Reading the two sides correctly
Ask three questions before you change anything:
- What does each side add, remove or modify? Compare the elements, not just the line count.
- Are the sides independent, as with
Tier__candSegment__c, or do they edit the same element, such as the same field with differenteditablevalues? - Did the surrounding lines change too? A conflict that includes a closing tag such as
</fieldPermissions>in only one half often means the two sides split an element differently.
If you need more context, git diff during a conflict shows a combined diff. Running git merge --abort returns you to the state before the merge if you want to start over.
git checkout --conflict=diff3 -- force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xmlThis rewrites the file with a third section, introduced by ||||||| and followed by the common ancestor. Seeing the original text tells you which side actually changed a line.
Common mistakes
- Treating the markers as XML. They are plain text, so a file that still contains them is not well-formed XML and will not deploy.
- Deleting only the
<<<<<<<and>>>>>>>lines and leaving=======. - Keeping both halves when they edit the same element, which creates duplicates.
Exercise
A conflict in a custom labels file shows <<<<<<< HEAD, a <labels> block for Greeting_Text, =======, a different <labels> block for Farewell_Text, then >>>>>>> release/spring. Which branch added Farewell_Text, and are the two sides likely to be independent?
Show answer
The release/spring branch added Farewell_Text, because it appears below the divider and above the marker that names it. The sides are independent since they add different labels, so Git only conflicted because both inserted at the same position.