Sub topic 10
Resolving Conflicts Deliberately
This chapter assumes you know how conflicts arise (the same component changed both locally and in the org) and that you can run sf project deploy start and sf project retrieve start against a scratch org. Here you will learn to resolve a conflict on purpose instead of overwriting one side by reflex.
Why Blind Overrides Lose Work
When tracking finds a component changed on both sides, the CLI stops and reports a conflict. The --ignore-conflicts flag removes that protection. Whichever side you run the command from wins, and the other side's edit is gone.
- Deploy with
--ignore-conflicts: your local file replaces the org version. - Retrieve with
--ignore-conflicts: the org version replaces your local file.
Neither command merges anything. So the safe order is to look first, decide second, and override last.
A Deliberate Resolution Workflow
Step 1: Preview both directions
sf project deploy preview --target-org my-scratch
sf project retrieve preview --target-org my-scratchThe preview lists each component, whether it would deploy or retrieve, and which ones are flagged as conflicts. Nothing changes in either place.
Step 2: Compare the two versions
Note the conflicting file names. Commit or stash your local work first so you can get it back. Then retrieve the org copy into a separate scratch location, for example a second project folder, and compare it with your file using a diff tool. If your project is under Git, a commit before you retrieve lets git diff show exactly what the org version changed.
Step 3: Choose one of three outcomes
- Keep local. Your version is correct. Deploy with the override:
``bash sf project deploy start --target-org my-scratch --ignore-conflicts ``
- Keep the org version. The org edit is correct, and your local change can be discarded. Retrieve with the override:
``bash sf project retrieve start --target-org my-scratch --ignore-conflicts ``
- Merge. Both sides have changes you need. Retrieve the org version, then re-apply your edit by hand (or restore it from Git), and deploy the merged file.
Step 4: Confirm the result
Run both previews again. A clean result shows no pending changes and no conflicts.
sf project deploy preview --target-org my-scratch
sf project retrieve preview --target-org my-scratchCommon Mistakes
- Overriding before previewing. The override flag hides which components were in conflict, so you cannot tell what you destroyed.
- Retrieving over uncommitted work. A retrieve with
--ignore-conflictsoverwrites local files with no undo unless Git holds a copy. - Applying the override to a whole project. The flag applies to every conflicting component in the command. Limit the command with
--source-diror--metadataif only one component needs it. - Resetting tracking to make the error disappear.
sf project reset trackinghides the conflict message but does not reconcile the files. The two versions still differ.
Exercise
A deploy fails with a conflict on one Apex class. Your local edit adds a new method, and a colleague changed a different method in the org. Which steps resolve this without losing either change?
Show answer
Run both previews to confirm the conflicting class. Commit your local file. Retrieve the org version, then re-apply your new method to it (or merge from Git). Deploy the merged file with --ignore-conflicts, since the conflict is already resolved by hand. Run both previews again to confirm there are no pending changes.