2

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 - Git diff doesn't ignore specified files in .gitignore

Appreciate help with this.

naib khan
  • 928
  • 9
  • 16
Varun SFDC
  • 143
  • 6

2 Answers2

0

Well .gitignore is used to ignore files you don't wanna push to the origin.

Don't git add the files u don't wanna push.

try git checkout -- filename for discarding the changes in files u have made.

Sagar Chaudhary
  • 1,343
  • 7
  • 21
  • Hello Sagar, So as you are suggesting, .gitignore doesn't play a role in git diff or git merge ? – Varun SFDC Aug 04 '19 at 05:27
  • This answer misses a lot of key aspects of `.gitignore`, but, @VarunSFDC, yes, `.gitignore` won't help with either diff or merge here. The `.gitignore` is not really about *ignoring* files at all (and hence is misnamed) but a correct name would be horribly long: dot-Git-here-are-files-that-if-they-are-untracked-right-now-don't-complain-about-them-and-don't-auto-add-them-with-en-masse-add-operations, or something like that. – torek Aug 04 '19 at 07:55
0

If you want to compare differences/ changes for specific folder or file please try the command bellow:

git diff your_branch1:path/to/folder your_branch2:path/to/folder

If you already have difftool configured, then you can also use: git difftool your_branch1:path/to/folder your_branch2:path/to/folder

For more you can explore this

Since git 1.9 something you can do exclude a specific file or folder

git diff branch_name  -- . ':(exclude)file_path_to_ignore_1' ':(exclude)file_path_to_ignore_2'

Note: For windows syntax use git diff branch_name -- . ":(exclude)file_path_to_ignore_1" (double quotes instead of single quotes)

naib khan
  • 928
  • 9
  • 16
  • Hello Naib, Thanks for your feedback. However, the thing is, Support, I want to compare a folder say, force-app which further has 3 folders - force-app/dir1, force-app/dir2 & force-app/dir3... However I want to skip comparison of force-app/dir2 as want to keep it intact. Hence, I was thinking about .gitignore Also, adding to it, eventually I would like to merge selected changes based on the o/p of git diff (if .gitignore helps me)... Do you recommend any guidelines I can follow for my scenario ? – Varun SFDC Aug 04 '19 at 05:30
  • If you compare for a folder, it will definitely do comparison for all the sub-folder/child-folder of parent folder. Please try atleast – naib khan Aug 04 '19 at 05:58
  • Hello Naib, I will surely try... But my point is if there is a way to skip comparison of any subfolder. – Varun SFDC Aug 04 '19 at 06:09
  • yes you can do this. please see edited answer :) its something like git diff branch_name -- . ':(exclude).gitignore' – naib khan Aug 04 '19 at 06:30