Sub topic 3
Resolving Conflicts Deliberately
Assume you know Salesforce DX project structure, have sf installed, and understand basic metadata and Git commands. Source tracking compares your local project with a tracked org. A conflict occurs when both sides changed the same component since the last synchronization.
Resolve conflicts deliberately
Preview both directions before changing anything:
sf project deploy preview --target-org my-scratch
sf project retrieve preview --target-org my-scratchReview the previews and decide which version should remain. Merge the changes in your local files when both versions contain useful work. Then deploy or retrieve again.
Handle deletes and renames
A deleted component is a change too. Confirm that the deletion is intentional before deploying it. A rename can appear as a delete followed by a new component, especially when metadata does not preserve rename information. Check the preview carefully so you do not remove the old component and accidentally lose related references.
Reset tracking state
Tracking data can become inconsistent after manual file changes, branch switches, or restoring an old project revision. After confirming that the local project and org should be treated as synchronized, reset tracking:
sf project reset tracking --target-org my-scratchThis changes the comparison baseline. It does not merge files or recover overwritten work, so save important changes in Git first.
Work without tracking
Sandboxes and other untracked orgs require explicit source selection. The CLI cannot calculate differences automatically.
sf project deploy start --target-org my-sandbox --source-dir force-app/main/default/classes
sf project deploy start --target-org my-sandbox --metadata ApexClass:MyClass
sf project deploy start --target-org my-sandbox --manifest manifest/package.xmlUse retrieve commands with equivalent selection flags when bringing metadata down.
Combine tracking with Git
Use Git as the durable history and review system. Use source tracking as a convenient comparison with a development org. Before switching branches, commit or stash local changes. Preview changes after switching, and let one person coordinate shared org changes to reduce conflicts.
Troubleshoot tracking problems
Check the target org, current branch, and force-app path first. Inspect .forceignore if expected files are missing. If the project and org have the same intended contents but previews remain wrong, commit or back up work, then reset tracking.
Exercise
A preview reports a conflict for an Apex class. What should you do before using --ignore-conflicts?
Show answer
Compare the local and org versions, preserve or merge the needed work, and choose deliberately which version to deploy or retrieve.