I have 2 branches in SFDX enabled project. mybranch and develop. I want to merge selected changes from develop and then merge those in mybranch. As a starting point I am trying to use git diff to see what all is extra in develop, however, it is mentioning files like .forceignore, .gitignore and all. And I want to compare only force-app folder. Is there any way I could make git diff & git merge to ignore a set of files & folder as .gitignore is not working. FYI, I have already gone through following and it doesn't help me - https://stackoverflow.com/questions/17820056/git-diff-doesnt-ignore-specified-files-in-gitignore

Appreciate help with this.


What I feel like is you are doing something wrong from the very beginning. You should include only the files you are interested in in your git repository and branch that to make the feature branch.

I am not quite sure whether my previous assumption is correct. But to your situation, I would recommend using git cherry-pick in this case. Follow this document here: https://git-scm.com/docs/git-cherry-pick You should be able to select a selection of changes to merge into develop.

| improve this answer | |
  • Hello Lance, Thanks for your response... I understand your view point however, it's just the constraint of scratch Org and SFDX Project because of which I am in this dilemma. I will definitely go through cherry-pick but something tells me there should be a reason .gitignore isn't working and that is bothering me – Varun SFDC Aug 4 '19 at 4:29
  • @VarunSFDC if I understand correctly, those are the files you want to include in your repository but don't want to compare and merge. Is that correct? – Lance Shi Aug 4 '19 at 4:31
  • Yes Lance.. exactly... dont want to merge and dont want to have as an o/p to git diff... struggling a bit though to achieve this as of now. – Varun SFDC Aug 4 '19 at 4:34
  • As far as I can tell, git diff is only for you to ignore files which you don't want to have them in your repository. To exclude the ones you don't want to merge, you need to use cherry-pick. I can be wrong though. But this is what I remember – Lance Shi Aug 4 '19 at 4:43
  • Thanks for the feedback Lance... I will go through cherry-pick. But for now I will keep the conversation open just in case someone can add on more. – Varun SFDC Aug 4 '19 at 4:45

Unfortunately, I could not understand much about cherry-pick for my scenario. However, below did helped me hence thought of sharing with you:

git diff scratchorg..develop --name-only -- . ":(exclude).gitignore"

and then

git checkout develop Filename

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.