Sub topic 7
Choosing between competing edits
This chapter assumes you can read Git conflict markers, know the Salesforce DX source format, and can keep XML well-formed while editing. It covers the case where both branches changed the same element in different ways, so keeping both sides is not an option.
Additive and competing edits
An additive conflict has two independent changes, such as two new fieldPermissions blocks. You keep both. A competing conflict has two changes to the same element, and only one value can survive. A permission set can grant editable as true or false for Account.Tier__c, but not both.
Git cannot tell these cases apart. It only sees that both sides changed the same lines. You decide which case you have by reading the XML.
Reading a competing conflict
Here, one branch made the field read-only and the other made it editable.
<fieldPermissions>
<<<<<<< HEAD
<editable>false</editable>
=======
<editable>true</editable>
>>>>>>> feature/new-field
<field>Account.Tier__c</field>
<readable>true</readable>
</fieldPermissions>Both versions are valid XML. Neither is wrong on its face. You have to find out which one is intended.
Deciding which side to keep
Work through these questions in order.
- What did each branch intend? Read the commit messages and the pull request descriptions.
- Does one change supersede the other? A later security fix usually beats an earlier convenience change.
- Who owns the decision? Access changes often need the person who requested them, not only the developer merging.
- Can you check the result in an org? A sandbox shows the real behavior.
To see each side's history for the file, use git log.
git log --oneline --merge -- force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xml
git show :1:force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xmlThe --merge option limits the log to commits that touched the conflicted file on either side. The :1: form shows the common ancestor, so you can see what each branch changed from the original.
Three possible outcomes
| Outcome | When to use it | Example |
|---|---|---|
| Keep our side | The current branch has the correct, intended value | A security restriction was added on purpose |
| Keep their side | The incoming branch has the correct, intended value | The feature branch fixes a wrong permission |
| Write a new value | Neither side is right alone | Combine a new label with a changed access level |
Applying the decision
To keep one side of a single conflict, delete the markers and the unwanted lines by hand. To keep one side for the whole file, use --ours or --theirs.
git checkout --ours -- force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xml
git add force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xmlUse this only when you are sure the whole file should come from one side. It discards the other side's non-conflicting changes too, including additions that Git had already merged cleanly.
Common errors
- Keeping the first side by habit, without checking the intent of the second.
- Using
--theirson a whole file and losing unrelated additions from your branch. - Removing the markers but leaving both
<editable>lines, which produces an invalid duplicate element. - Committing without a dry run, so a resolved value that the org rejects goes unnoticed.
Exercise
Two branches changed the same <editable> value for Account.Tier__c. Git reports a conflict. What are two things you should do before choosing a side, and why shouldn't you run git checkout --theirs on the whole file as a shortcut?
Show answer
First, read the commit messages or pull requests for both branches, and view the common ancestor with git show :1:<path>, to learn what each branch intended. Optionally confirm with the person who owns the access decision. Taking --theirs for the whole file replaces everything in your version, including your branch's other changes that merged cleanly, so you would lose work that was never in conflict.