Sub topic 14
Source-tracking conflicts versus Git conflicts
This chapter assumes you can merge branches in Git and run sf commands against a scratch org or a sandbox with source tracking enabled. Both kinds of conflict are called "conflicts", but they happen in different places and are fixed differently.
Two different comparisons
A Git conflict happens between two branches. Git cannot combine two edits to the same lines, so it stops the merge and writes markers into the file.
A source-tracking conflict happens between your local project and an org. Salesforce CLI records which components changed locally and which changed in the org. If the same component changed on both sides since the last sync, the CLI refuses to deploy or retrieve it. Git is not involved at all.
| Question | Git conflict | Source-tracking conflict |
|---|---|---|
| What is compared? | Two branches | Local files and an org |
| Who detects it? | Git | Salesforce CLI |
| What does it look like? | `<<<<<<<` markers in the file | A conflict error from `sf project deploy start` or `sf project retrieve start` |
| Where do you fix it? | In the file, then `git commit` | By choosing deploy or retrieve, then syncing |
A typical source-tracking conflict
Suppose an admin edits the Sales_Access permission set in your scratch org. You edit the same file locally and run a deploy. The CLI stops because both sides changed the component.
Preview what would happen in each direction before you decide.
# See what a deploy would send and which components conflict
sf project deploy preview --target-org my-scratch
# See what a retrieve would pull and which components conflict
sf project retrieve preview --target-org my-scratchBoth previews list conflicts separately from ordinary changes. Read the list first, because the next step overwrites one side.
Choosing a side
You have two ways to settle a source-tracking conflict.
- Keep the org version. Retrieve the component with
--ignore-conflicts. This overwrites your local file, so commit or stash your edits first. - Keep the local version. Deploy with
--ignore-conflicts. This overwrites the org's change, so confirm the admin's edit is not needed.
# Keep the org's version: overwrite local files
sf project retrieve start --ignore-conflicts --target-org my-scratch
# Keep your local version: overwrite the org
sf project deploy start --ignore-conflicts --target-org my-scratchIf the two edits are different and both matter, do not use either flag blindly. Retrieve the org version onto a separate branch, then merge it with Git. That turns the problem into a Git conflict, and you can resolve it with the markers and validation steps from earlier chapters.
How the two kinds interact
A Git merge changes files on disk, but it does not tell the org or the tracking records. After a merge, the CLI may report changes that came from the other branch, or conflicts for components the org already has. This is normal. Run a preview, then deploy to the org so the org and your files agree again.
Tracking also gets out of step when you switch branches in a long-lived sandbox. If the CLI reports conflicts you cannot explain, reset the tracking so it matches the org or a revision you choose.
sf project reset tracking --target-org my-scratchResetting changes only the CLI's records. It does not change your files or the org. After a reset, you must check by hand that your files and the org match. Treat it as a last step, not a first one.
Exercise
You merge a branch with no Git conflicts. Then sf project deploy start stops because the Sales_Access permission set also changed in your scratch org. What kind of conflict is this, and what should you do first?
Show answer
It is a source-tracking conflict, because Git finished the merge and the CLI found a component changed on both sides. Run sf project deploy preview and sf project retrieve preview to see the conflicts. If the org's change matters, retrieve it onto a separate branch and merge it with Git. Otherwise deploy with --ignore-conflicts after committing your work.