Sub topic 1
How Git Detects and Reports Merge Conflicts
Prerequisites
You should know basic Git commands such as branch, commit, merge, and status. You should also recognize a Salesforce DX project and understand basic XML elements and nesting.
How Git Detects and Reports Merge Conflicts
Git compares changes when it combines two branches. If both branches change the same lines, or nearby lines that Git cannot combine safely, Git pauses the merge. Git does not understand Salesforce metadata rules. It compares text.
git merge feature/new-field
# 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=UA file shown as both modified still contains unresolved changes. You must resolve it before Git can create the merge commit.
Salesforce DX Source Format: What the Files Look Like
Salesforce DX source format stores metadata as readable files under directories such as force-app/main/default. A permission set, for example, uses XML with repeated fieldPermissions elements.
<?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>
<label>Sales Access</label>
</PermissionSet>The XML structure matters. Every opening element needs a matching closing element, and Salesforce expects particular element names and values.
Why Salesforce Metadata Conflicts So Often
Metadata files conflict more often than ordinary application code because teams frequently edit the same central files. Profiles and permission sets collect many independent permissions in one XML document. Salesforce may also rewrite or reorder metadata during retrieval or deployment.
Conflicts are especially likely when:
- Two branches add elements at the same location.
- One branch changes a permission while another changes the same permission.
- Salesforce reorders repeated XML elements.
- A large file changes because of a small administrative update.
The change may be logically independent, but Git only sees nearby text.
Reading Conflict Markers in Metadata XML
Git places three marker types around competing text:
<<<<<<< HEADstarts the current branch version.=======separates the two versions.>>>>>>> feature/new-fieldends the incoming branch version.
<<<<<<< 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-fieldThese markers are instructions for you, not valid XML. Remove them and choose the correct content. If both additions are required, keep both complete fieldPermissions blocks.
Exercise
Which section of the conflict block represents the branch you were already on?
Show answer
The section between <<<<<<< HEAD and ======= represents the current branch.