When working with
sfdx force:source:statusthe documentation cites as exemplary result:
STATE FULL NAME TYPE PROJECT PATH Local Deleted MyClass ApexClass /MyClass.cls-meta.xml Local Deleted MyClass ApexClass /MyClass.cls Local Add OtherClass ApexClass /OtherClass.cls-meta.xml Local Add OtherClass ApexClass /OtherClass.cls Local Add Event QuickAction /Event.quickAction-meta.xml Remote Deleted MyWidgetClass ApexClass /MyWidgetClass.cls-meta.xml Remote Deleted MyWidgetClass ApexClass /MyWidgetClass.cls Remote Changed (Conflict) NewClass ApexClass /NewClass.cls-meta.xml Remote Changed (Conflict) NewClass ApexClass /NewClass.cls
On conflicts, the docs say
Notice that you have a conflict. […] In this new development paradigm, the local project is the source of truth. Consider if it makes sense to overwrite the conflict in the scratch org.
In addition to that approach, I want to learn how to efficiently diff local vs. remote conflicts in Salesforce DX.
As far as I understand, when Salesforce released SFDX they did it to provide a way for developers to easily integrate a Version Control System (VCS) in their development cycle, as well as many other reasons.
Therefore, if you’re developing using SFDX, it would make much more sense to integrate it with Git, Mercury, TFS or whichever VCS you prefer and directly diff the branches, not local code vs org code.
One of the best advantages of SFDX is that you no longer have the organization as the source of truth but the actual VCS repository – that’s why Salesforce recommends overwriting whatever is in the org always. It’s a bad practice to toggle the source of truth from VCS to org and back.
Now, regarding the diffing, in git, to diff local branch to remote, it’s as easy as executing
git diff <masterbranch_path> <remotebranch_path> or simply use a visual tool like Sourcetree.
EDIT – Comparing a previous commit with server code
So, let’s say you’ve made three commits in local and pushed them to remote (A, B and C in this order) but you want to compare commit B with whatever you have in the server (Salesforce Org) to see what has changed. In that case the best approach imo would be to retrieve your SF metadata to local and then diff with that commit with the
git diff command, or a visual tool if you prefer. The command would look like:
git diff a772eb592db224f4b8688d629223f9d16739bebf
Being that long string the revision number/hash of the commit.
As I’ve already said… got for visual tools since you can do it with a couple of clicks without having to copy-paste large strings like the latter.
The main advantage of going for this approach vs the typical local/server diff we’re used to is that we have every single change ever done to our code tracked by git, allowing us to perform very powerful diffs as well as reverts, etc.
BTW, take into account that whenever you pull your code from your Salesforce instance to local you will be overwritting everything, so if you have uncommitted work, you might want to at least stash it before retrieving in order to not loose work.
I hope this answers your question 🙂