Sub topic 4
Where Tracking State Lives on Your Machine
This chapter assumes you have a Salesforce DX project, the sf CLI installed, and an authorized scratch org or sandbox with tracking enabled. You should also know basic Git and shell commands.
Source tracking compares two things: a record of changes kept by the org, and a local snapshot kept by the CLI. This chapter covers the local half. Knowing where it is stored helps you explain odd preview results and fix a project that has fallen out of sync.
The .sf directory
The CLI stores its project-level state in a hidden folder named .sf at the root of your project, next to sfdx-project.json. Older projects may also have a .sfdx folder from the previous CLI generation. Tracking data sits inside this folder, in a subfolder for each org.
ls -a
ls .sf/orgsEach folder under .sf/orgs is named with the org ID. The exact file names inside can change between CLI versions, so treat them as internal details. What matters is what the files hold:
- The last org revision number the CLI has seen for each component.
- A hash (a short fingerprint) of each local file at the time of the last deploy or retrieve.
- The list of components that were last synchronized.
How the snapshot is used
When you run a preview, deploy, or retrieve, the CLI does two comparisons. It hashes your current local files and compares them with the stored hashes to find local changes. It also asks the org for components whose revision number is newer than the stored one to find remote changes. A component that differs on both sides is a conflict.
Because the snapshot lives on your machine, tracking is per project folder and per org. Two clones of the same repository each keep their own snapshot, so one clone can show changes that the other has already deployed.
Keep .sf out of Git
The .sf folder describes your machine's relationship with one org. Do not commit it. A new Salesforce DX project already lists it in .gitignore. If yours does not, add it:
.sf/
.sfdx/Inspecting and resetting state
You rarely edit the folder by hand. Use the CLI instead. To see what the snapshot thinks has changed, run a preview:
sf project deploy preview --target-org my-scratch
sf project retrieve preview --target-org my-scratchIf the snapshot is wrong, for example after a clone, a restore, or a manual .sf deletion, reset it with the CLI:
sf project reset tracking --target-org my-scratchThis tells the CLI to treat the org and your local files as synchronized at the chosen revision. Run it only after you have reviewed the previews, because any differences that exist at that moment stop being reported.
If you delete .sf entirely, the CLI loses the snapshot for every org in the project. Previews will then treat all local files as changed until you reset tracking or deploy again.
Exercise
A teammate copies their project folder, including .sf, to a new laptop. Their preview now reports conflicts for components nobody edited. What is the likely cause, and what should they do?
Show answer
The copied snapshot holds revision numbers and hashes that no longer match the org or the new files, so the CLI sees differences on both sides. They should review sf project deploy preview and sf project retrieve preview to confirm the real differences, then run sf project reset tracking --target-org <alias> and keep .sf out of version control.