Sub topic 7
Choosing between competing edits
This chapter assumes you can run basic Git merges, read conflict markers, and keep Salesforce metadata XML well-formed. It also assumes you can run sf commands against a sandbox. The previous chapter covered conflicts where both branches add something new. Here both branches changed the same element, so keeping both sides is no longer safe.
What makes an edit "competing"
An additive conflict has two independent changes that happen to touch the same lines. A competing conflict has two changes that answer the same question differently. Examples:
- One branch sets a custom label value to
Welcome back. The other sets it toWelcome to Acme. - One branch gives a permission set edit access to
Account.Tier__c. The other makes the same field read-only. - Both branches change the
<defaultValue>of the same field.
If you keep both sides, you get duplicate elements. The deployment then fails, or the later element silently wins. You have to choose, and the choice is a product decision, not an XML decision.
Step 1: Find what each side meant to do
Git shows only the two end states by default. You also need the common ancestor (the base) and the intent of each commit.
Turn on the three-way marker style so the base appears in the conflict. zdiff3 needs Git 2.35 or later. Use diff3 on older versions.
git config --global merge.conflictStyle zdiff3
git checkout --merge -- force-app/main/default/labels/CustomLabels.labels-meta.xmlThe second command recreates the conflict markers in that file with the new style. It discards any edits you made to it, so run it only if you have not resolved the file yet.
Then read the commits on each side that touched the file:
git log --merge --oneline -- force-app/main/default/labels/CustomLabels.labels-meta.xml
git log --merge -p -- force-app/main/default/labels/CustomLabels.labels-meta.xml--merge limits the log to commits that touch conflicted files from both sides of the merge. The commit messages and linked tickets usually tell you which change is current.
You can also read the three versions Git keeps in its index:
| Stage | Meaning | Command |
|---|---|---|
| 1 | Common ancestor (base) | `git show :1:<path>` |
| 2 | Your branch (`ours`, the `HEAD` side) | `git show :2:<path>` |
| 3 | The branch being merged (`theirs`) | `git show :3:<path>` |
Step 2: Read a three-way conflict
Here is a custom label that both branches changed from the same starting value:
<?xml version="1.0" encoding="UTF-8"?>
<CustomLabels xmlns="http://soap.sforce.com/2006/04/metadata">
<labels>
<fullName>Welcome_Banner</fullName>
<language>en_US</language>
<protected>false</protected>
<<<<<<< HEAD
<shortDescription>Welcome banner on the home page</shortDescription>
<value>Welcome back</value>
||||||| base
<shortDescription>Welcome banner</shortDescription>
<value>Welcome</value>
=======
<shortDescription>Welcome banner</shortDescription>
<value>Welcome to Acme</value>
>>>>>>> feature/rebrand
</labels>
</CustomLabels>The base section shows what each side started from. Comparing it to each side tells you what each side actually changed:
HEADchanged the description and the value.feature/rebrandchanged only the value.
The two sides disagree on <value>. Only HEAD changed <shortDescription>, so Git would normally merge that line cleanly. It is in the conflict because the two changes are adjacent lines. You can keep the new description and still choose between the values.
Step 3: Decide
Every resolution is one of four moves.
| Move | Use it when | Example |
|---|---|---|
| Keep ours | Your branch's value is the current decision | The `HEAD` value is newer or approved |
| Keep theirs | The incoming branch is the current decision | The rebrand replaces the old text |
| Combine parts | The sides changed different attributes of one element | New description from one side, new value from the other |
| Write a new value | Neither side is right once both are known | A compromise label text agreed with both authors |
A fifth option exists for files that are generated and awkward to merge, such as page layouts. You can re-retrieve the file from an org. A later chapter covers that.
For the label above, suppose the team confirms that the rebrand text is current but the new description is still wanted. The result combines both sides:
<?xml version="1.0" encoding="UTF-8"?>
<CustomLabels xmlns="http://soap.sforce.com/2006/04/metadata">
<labels>
<fullName>Welcome_Banner</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Welcome banner on the home page</shortDescription>
<value>Welcome to Acme</value>
</labels>
</CustomLabels>You deleted all four marker lines and both of the other <value> and <shortDescription> lines. Exactly one of each element remains.
Step 4: Check dependent values
Some elements cannot be chosen independently. A permission set conflict shows the problem. One branch grants edit access and the other removes read access:
<fieldPermissions>
<<<<<<< HEAD
<editable>true</editable>
<field>Account.Tier__c</field>
<readable>true</readable>
=======
<editable>false</editable>
<field>Account.Tier__c</field>
<readable>false</readable>
>>>>>>> feature/lock-tier
</fieldPermissions>Taking editable from HEAD and readable from the other branch looks like a valid combination of parts. It produces editable=true with readable=false. Salesforce rejects that, because edit access requires read access. Pick the two values from the same side unless you know the dependency holds.
The same applies to other related settings:
- Profile and permission set object permissions, where
allowEditneedsallowRead, andallowDeleteneedsallowEdit. - Field-level
<required>and<defaultValue>. - Record type picklist values and a record type's active state.
Taking a whole side from the command line
If you have decided that one side wins for an entire file, skip the manual edit:
git checkout --ours -- force-app/main/default/labels/CustomLabels.labels-meta.xml
git checkout --theirs -- force-app/main/default/labels/CustomLabels.labels-meta.xml
git add force-app/main/default/labels/CustomLabels.labels-meta.xmlRun only one of the first two commands.
--ours and --theirs are whole-file choices. They discard all of the other side's changes in that file, including non-conflicting ones that Git had already merged. If the other branch also made unrelated additions to the file, you lose them without any warning. When in doubt, resolve by hand, or run git diff against the other branch afterwards to see what you dropped.
Ours and theirs also swap during a rebase. In git rebase, --ours is the branch you are rebasing onto and --theirs is your own commit being replayed. Check which operation is in progress before using either flag.
Step 5: Verify before you commit
After resolving each file, confirm three things:
- No marker lines remain:
grep -nE '^(<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|)' <file>. - The XML still parses:
xmllint --noout <file>. - Each element you chose appears once. Search for the
fullNameorfieldvalue and count the matches.
A dry-run deployment to a sandbox then checks the values against Salesforce's own rules, including dependencies like the one above. The next chapters cover the dry run in detail.
Common errors
- Keeping both blocks of a competing edit. The deploy fails with a duplicate value error, or the later element silently overrides the earlier one.
- Mixing values across sides. You produce a combination neither author tested, as in the permission example.
- Leaving the
basesection behind. Withdiff3orzdiff3there are four marker types, not three. A leftover|||||||line makes the XML invalid. - Using
--theirsduring a rebase. You keep the wrong side because the meaning of the flag is reversed.
Exercise
A merge conflict in a permission set shows HEAD with <editable>false</editable> and <readable>true</readable> for Account.Tier__c. The other branch has <editable>true</editable> and <readable>false</readable> for the same field. Both authors say their change is needed. Why is taking editable from one side and readable from the other a bad resolution, and what should you do instead?
Show answer
Taking editable=true from one side and readable=false from the other gives an invalid combination, because edit access requires read access, so the deployment would fail. Values that depend on each other must come from the same side. Because both authors claim their change is needed, ask them what access the field should have, write that single consistent pair (for example editable=false, readable=true, or editable=true, readable=true), and validate it with a deployment dry run.