Sub topic 15
Troubleshooting Common Tracking Problems
This chapter assumes you can use sf project deploy start and sf project retrieve start. It also assumes you know what a tracked org is (a scratch org or a tracked sandbox) and that you have met conflicts and .forceignore in earlier chapters. Here you will learn a repeatable way to diagnose tracking problems and the usual fixes for each.
A diagnostic routine
Most tracking problems have one of five causes:
- The org does not support tracking.
- The local tracking files do not match the org.
- A real conflict exists between local and org changes.
- A
.forceignorepattern hides a file. - A delete or rename was not handled as a change.
Work through these in order before you reach for --ignore-conflicts or a reset. Both of those discard information, so use them last.
Always start with the preview
The preview commands change nothing, so they are the safest first step. They show what would deploy, what would be retrieved, and which components conflict.
sf project deploy preview --target-org my-scratch
sf project retrieve preview --target-org my-scratchRead the output as three groups: local changes to deploy, org changes to retrieve, and conflicts. If the result is not what you expect, the cause is usually in one of the sections below.
Problem: nothing deploys or retrieves, or everything does
The command may report that there is nothing to deploy when you know you edited a file. It may also try to move every component. Check these in order.
The org is not tracked
Tracking works only for scratch orgs and for sandboxes that have source tracking enabled. In other orgs, such as production and sandboxes without tracking, the CLI cannot compute changes. A command with no source flags then has nothing to select, so it fails or does nothing.
The fix is to name what you want:
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.xmlIf you expected tracking, confirm the org type. A sandbox created without tracking will not gain it by itself, so you either work with explicit source selection or use a sandbox that has tracking enabled.
A `.forceignore` pattern hides the file
A file that matches a .forceignore pattern is skipped by both deploy and retrieve. It will never appear in a preview. This is a common cause of "my change is ignored."
**/jsconfig.json
**/.eslintrc.json
**/__tests__/**Check each pattern against the path of the missing file. A broad pattern such as **/__tests__/** hides everything under any folder with that name. Edit the pattern, then run the preview again.
The file is outside a package directory
The CLI reads only directories listed under packageDirectories in sfdx-project.json. A file outside those directories is not part of the project, so it is never tracked. Move it into a package directory, or add the directory to the project file.
Tracking state was lost
If you deleted the .sf directory, cloned the project onto a new machine, or switched to another copy of the project, the local snapshots are gone. The CLI can no longer tell which org changes you have already seen. You may then see a long list of components as changed. Do not deploy that list. Review it with the preview commands first. Then decide whether to reset tracking, as described below.
Problem: conflicts you did not expect
A conflict means the same component changed both locally and in the org since the last sync. The CLI stops so that one side does not silently overwrite the other.
Unexpected conflicts usually come from one of these:
- A teammate or an admin changed the component in the org through Setup.
- You retrieved or deployed some components with explicit flags and the tracking state for others was not updated as you assumed.
- Salesforce changed a component itself, for example when a package, a feature, or a setting modified related metadata.
- The local file changed only in whitespace or ordering, which still counts as a local change.
To handle it:
- Run both preview commands and note the conflicting components.
- Compare the local file with the org version. You can retrieve the org version into a scratch folder or a separate branch.
- Decide which side is correct, or merge by hand.
- Only then run the command with
--ignore-conflicts.
sf project deploy start --target-org my-scratch --ignore-conflicts
sf project retrieve start --target-org my-scratch --ignore-conflictsProblem: deletes and renames behave oddly
A delete or a rename is a change like any other, but its effects can surprise you.
- Deleting a local file. The CLI sees that a tracked component is gone locally. It lists the component as a pending delete in the preview. A deploy may not remove the component from the org unless the delete is deployed as a deletion. Check the preview and the command output to confirm the component was actually removed.
- Deleting in the org. A retrieve reports the deletion. It removes the matching local files, so check Git status afterward.
- Renaming. Metadata has no rename operation. A rename appears as a delete of the old name and an add of the new name. If other components reference the old name, such as a page layout that references a field, the deploy can fail on those references. Update the references first or deploy them together.
After any delete or rename, run both previews again. If the lists are empty, the two sides agree.
Problem: histories no longer match
Sometimes the local tracking state and the org's revision history disagree, and no conflict resolution fixes it. Typical triggers include restoring a project from backup, switching between several clones of the same project, or an org that was refreshed or recreated under the same alias. The symptoms are conflicts on components you never touched, or changes that never clear from the preview.
Reset tracking:
sf project reset tracking --target-org my-scratchThis tells the CLI to treat the org and your local project as synchronized at the chosen revision. It does not move any files. If the two sides actually differ at that moment, the CLI will no longer report those differences, so you must make them match yourself.
A safe sequence:
- Commit or stash your local work in Git.
- Run both previews and save the output.
- Retrieve the org's current state into a clean branch and compare it with your branch.
- Merge what you want to keep.
- Reset tracking.
- Run both previews again. They should now report no changes.
Problem: the org alias points to the wrong org
If an alias was reused for a new scratch org, the local tracking files may still describe the old one. Check which org the alias points to before you diagnose anything else.
sf org list
sf org display --target-org my-scratchConfirm the username and org ID match the org you intend to use. If you created a new scratch org under an old alias, treat the tracking state as stale. Delete the old local tracking files or reset tracking, then deploy the whole project to the new org once.
Quick reference
| Symptom | Likely cause | First action |
|---|---|---|
| "Nothing to deploy" after an edit | `.forceignore` match, file outside package directory, or untracked org | Check the pattern, the path, and the org type |
| Command needs source flags | Org has no tracking | Use `--source-dir`, `--metadata`, or `--manifest` |
| Long list of unexpected changes | Tracking files missing or from another copy | Preview, compare, then reset |
| Conflict on a component you did not edit | Org-side change or a stale history | Compare versions before any override |
| Deleted file remains in the org | Delete was not deployed as a deletion | Check the preview and the deploy output |
| Deploy fails after a rename | References to the old name | Update references or deploy them together |
| Conflicts return after each sync | Alias reused or histories diverged | Verify the org, then reset tracking |
Habits that prevent problems
- Run the previews before each deploy or retrieve.
- Commit before using
--ignore-conflictsor a reset. - Keep one working copy of the project per org, or reset tracking when you switch.
- Keep
.forceignoreshort and specific. - Agree with your team on who changes metadata in the org directly.
Exercise
You run sf project deploy start --target-org my-scratch and the CLI reports a conflict on MyClass. You are sure your local version is correct. What do you do before you run the command with --ignore-conflicts, and why?
Show answer
Commit your local work to Git, run sf project retrieve preview and sf project deploy preview, and compare the org version of MyClass with your local file. The org version may contain a teammate's or admin's change. --ignore-conflicts overwrites the org with your file, and you cannot recover the org version if you never looked at it or saved it.
Exercise
After restoring your project from a backup, the preview lists dozens of components you never changed. What is the likely cause, and what safe steps lead to a clean state?
Show answer
The local tracking state in the .sf directory no longer matches the org's revision history. Commit your work, retrieve the org's current state into a separate branch, compare it with your branch, and merge what you want to keep. Then run sf project reset tracking --target-org my-scratch and run both previews again. They should report no changes.