Sub topic 9
How conflicts arise
This chapter assumes you have a Salesforce DX project, an authorized scratch org or sandbox with tracking enabled, and basic comfort with sf project deploy and sf project retrieve. It covers how a conflict forms. The next chapter covers how to resolve one.
What a conflict is
A conflict exists when the same component has changed on both sides since the last sync. The CLI cannot tell which version you want, so it stops the operation instead of overwriting either one.
Tracking compares three things for each component:
- The local file now.
- The local snapshot recorded at the last deploy or retrieve.
- The org's revision counter for that component.
If the local file differs from its snapshot, the component has a local change. If the org's revision is newer than the one the CLI last saw, it has a remote change. A component with both is in conflict.
A worked example
Suppose you have an Apex class AccountService in a tracked scratch org, and both sides are in sync.
- You edit
AccountService.clslocally and add a method. You do not deploy yet. - A teammate, or you in Setup, edits the same class in the org's Developer Console.
- You run
sf project deploy start --target-org my-scratch.
The deploy fails and reports the conflict. Nothing is written to the org. The same happens in reverse if you run sf project retrieve start while the local file has unsynced edits.
Detecting conflicts before they hit you
Run the preview commands first. They list local changes, remote changes, and conflicts without changing anything.
sf project deploy preview --target-org my-scratch
sf project retrieve preview --target-org my-scratchIn the output, a component appears in the conflict list when both sides changed it. Make a habit of previewing before a deploy, especially in a shared org.
Common causes
| Situation | Why it conflicts |
|---|---|
| Two developers share one scratch org | Each one's local edits clash with the other's org edits |
| Quick fix made in Setup, then local edits | The org revision moved while your snapshot stayed old |
| Pulling a Git branch that changes tracked files | Local files change without a deploy, so they differ from the snapshot |
| Switching branches back and forth | Files change locally, while the org still holds the other branch's version |
| Deleting `.sf` or reusing it with another org | The snapshot no longer matches the org's history |
Not every difference is a conflict. If only the local side changed, the component is a plain local change. If only the org changed, it is a plain remote change. Both sides must differ.
Overriding is a decision, not a fix
Both commands accept --ignore-conflicts.
sf project deploy start --target-org my-scratch --ignore-conflicts
sf project retrieve start --target-org my-scratch --ignore-conflictsThis makes one side overwrite the other and discards the losing version. Use it only after you have read the preview and know which version should win.
Exercise
You edit AccountService.cls locally. Then a colleague edits the same class in your shared scratch org. Which command shows this before you deploy, and what does it do to the org?
Show answer
sf project deploy preview --target-org my-scratch. It lists the component as a conflict because both the local file and the org revision changed since the last sync. It does not change the org or your local files.
Exercise
You run git pull and it updates several Apex classes. You have not deployed anything. Can this lead to conflicts, and why?
Show answer
Yes, if someone also changed those classes in the org. The pulled files now differ from the CLI's local snapshot, so they count as local changes. If the org's revisions are also newer, the components are in conflict.