Sub topic 14
Deploying Only What Changed
This chapter assumes you have read the earlier chapters on pull request validation and release promotion. You should know how sf project deploy start works and how release tags mark what reached production.
Why deploy a delta
A full deployment sends every component in force-app. In a mature project that means thousands of files, long upload times, and a bigger chance that an unrelated component fails the deployment. A delta deployment sends only the components that changed between two Git commits. Because Git already records what changed, the diff can drive the deployment.
Delta deployment has two jobs in this workflow:
- It makes pull request validation faster.
- It makes releases smaller and easier to reason about.
Choosing the comparison points
A delta is a comparison between two Git references. The right pair depends on the job.
| Job | From | To |
|---|---|---|
| Pull request validation | `origin/main` | The pull request head |
| Release to production | The last release tag | The commit being released |
The release row matters. If you compare against the previous commit, you can skip changes that were merged but never deployed. The last release tag marks what production actually has, so the delta covers everything since then.
Generating a delta with sfdx-git-delta
The Salesforce CLI has no built-in Git diff deployment. A common choice is the open source plugin sfdx-git-delta. It is a third-party tool, so pin its version in your pipeline.
sf plugins install sfdx-git-delta
sf sgd source delta --from v2026.11.3 --to HEAD --output-dir delta --generate-deltaThe plugin writes two manifests:
delta/package/package.xmllists components that were added or modified.delta/destructiveChanges/destructiveChanges.xmllists components that were deleted.
With --generate-delta, it also copies the changed source files into the output directory.
Deploying the delta
Pass the manifest to the deploy command. Deleted components go through the destructive changes option.
sf project deploy start \
--manifest delta/package/package.xml \
--post-destructive-changes delta/destructiveChanges/destructiveChanges.xml \
--test-level RunLocalTests \
--target-org ci-org \
--wait 60Add --dry-run to turn this into a check-only validation, as in the pull request check from the earlier chapter. Run the plugin step before the deploy step in that workflow.
Common errors and limits
- Missing dependencies. A changed Apex class may reference a field that is not in the delta. If the target org lacks that field, the deployment fails. This usually means the target org has drifted from
main. - Wrong base reference. Comparing against the wrong tag or branch gives a delta that is too large or too small. Check the generated
package.xmlbefore you trust it. - Deletions. Without the destructive manifest, removed components stay in the org and cause drift.
- Test coverage. A delta changes what is deployed, not the test rules. Production still requires tests to run and meet coverage.
- Shallow clones. CI checkouts often fetch only the latest commit. Set
fetch-depth: 0onactions/checkout, or the diff cannot see the older reference.
Exercise
A release to production should include everything merged since the last deployment. Which --from reference should the delta use, and why would HEAD~1 be wrong?
Show answer
Use the last release tag, because it marks what production already has. HEAD~1 covers only the most recent commit, so any earlier merged change that was never deployed would be left out of the delta.