Sub topic 6
Keeping both sides when changes are additive
This chapter assumes you can run basic Git merges, read a Salesforce DX project layout, and understand XML nesting. It covers the most common conflict in metadata files: two branches each added something new at the same spot.
What an additive conflict is
An additive conflict happens when both branches insert new, independent elements at the same position. Git cannot tell whether order matters, so it stops and asks you. In metadata XML the two additions usually don't affect each other. Adding a field permission for Account.Tier__c on one branch and Account.Segment__c on another is a typical case.
Here is the merge that stops, and the command that lists the files still in conflict.
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=URecognizing the pattern
Open the file. Each branch added a whole fieldPermissions block at the same position, so both versions sit between the markers.
<?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>The section between <<<<<<< HEAD and ======= is your current branch. The section between ======= and >>>>>>> feature/new-field comes from the branch you are merging in. The checks that tell you it is additive:
- Each side contains complete, self-contained elements.
- The two sides refer to different things (
Tier__candSegment__c). - Neither side deletes or edits a line that exists in the common ancestor.
Keeping both sides
To resolve it, keep both blocks and delete the three marker lines: <<<<<<<, ======= and >>>>>>>. Leave everything else untouched.
<?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>
<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>
<label>Sales Access</label>
</PermissionSet>Checking before you commit
Removing markers is easy to get subtly wrong, for example by leaving one behind or cutting a closing tag. Run these checks, then finish the merge.
# Check that no conflict markers remain
grep -rnE '^(<<<<<<<|=======|>>>>>>>)' force-app
# Check that a resolved file is still well-formed XML
xmllint --noout force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xml
# Validate against the target org without saving changes
sf project deploy start --dry-run --source-dir force-app --target-org my-sandbox
# Finish the merge
git add force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xml
git commitCommon errors
- Keeping both sides when both blocks name the same
<field>. That produces a duplicate entry, and it is a competing edit, not an additive one. - Deleting only the marker lines you noticed. The
grepcheck catches the rest. - Resolving in the middle of an element, so the file no longer parses.
xmllintcatches this.
Exercise
A conflict has <field>Account.Tier__c</field> inside a fieldPermissions block on one side and the same field with <editable>true</editable> on the other side. Should you keep both sides unchanged? Why?
Show answer
No. Both sides name the same field, so the edits compete and keeping both would create a duplicate entry for Account.Tier__c. Decide which permission values are correct and keep a single block.