How to forceignore a whole folder, except a specific file in your DX Project
⏱ 2 min. readIntro to the issue
Have you ever worked with scratch orgs and wondered how you could ignore all changes to a specific folder (e.g Profiles), except to just one specific file in that folder, let’s say System Admin profile?
The first thing that comes into your mind is copy-pasting all the file paths that you want to ignore, except the one that you want to NOT ignore. This would result on having a lot of lines, making the .forceignore file a lot longer and not so easily readable.
Don’t rush and do that, because there is a better solution to it 🎉
The Solution
We can use the exclamation point “!” to make the specific exclusion, just like we would use it in our validation rules, apex or in a .gitignore file.
⬇️ Below is the example snippet you could copy into your .forceignore file
1 | force-app/main/default/profiles/** |
So, above we are ignoring every change in every profile, except to the System Admin one.
Example to try out
- Add the above snippet to your .forceignore file
- Create and open a fresh scratch org
- Go to profiles and modify the System Admin and also the Standard User profiles.
- Save the changes.
- Jump to vscode and pull the changes from your scratch org with:
1
sfdx force:source:pull -f
- You will notice that the CLI will only pull the changes to the System Admin profile 🙌🏼
You can of course use this example with all other folders and files in your DX project with just a few simple adjusments.
Sources
1️⃣ Salesforce DX Developer Guide
2️⃣ Salesforce Stackexchange
3️⃣ salesforce cli issue
Disclaimer
The articles posted in this blog assume that you already have a deep developer knowledge. This is why I do not explain things more thoroughly, but just give out the solution.