1

I've seen many examples and they pretty much say the same but for some reason I cannot get it to work using SourceTree. My folder structure shown below, i want to ignore everything except for folder3 and all it's content, folder2_3_2_1, all it's content and the .ignore file.

folder1
folder2
   folder2_1
   folder2_2
   folder2_3
     folder2_3_1
     folder2_3_2
          folder2_3_2_1
             someOtherFile1.php
             someOtherFile12php
             someNewFolder
     folder2_3_3
   folder2_4
folder3
.ignore
somefile.php
somefile2.php

in my .ignore I have the following

# Ignore everything
/*

#except for
!.gitignore
!folder3/
!folder2/folder2_3/folder2_3_2/

Strange thing is, if I don't ignore anything and I'm able to see all my files in my unstaged files panel, if I right click and ignore someOtherFile.php and select the option to ignore everything beneath, it does the opposite, sourceTree ignores it's folder (i.e. folder2_3_2_1) and everything within!

SourceTree V 2.3.1.0

Thank you in advance

david-l
  • 623
  • 1
  • 9
  • 20

1 Answers1

2

If understood what you want to do, you have to put in file .gitignore the following lines:

# Ignore everything
*

#except for
!.gitignore
!folder3/
!folder3/*
!folder2/
!folder2/folder2_3/
!folder2/folder2_3/folder2_3_2/
!folder2/folder2_3/folder2_3_2/*
!folder2/folder2_3/folder2_3_2/*/*

This because you have to cite both the directories and the contents.

Details

folder3

So, when you write

!folder3/

you are saying that folder3 is to be considered, but not its contents, and since empty directories are not versioned... it is useless

you have to write

!folder3/
!folder3/*

if there are subdirectories inside folder3 you have to add one line for each level:

!folder3/*/*
!folder3/*/*/*

etc. etc.

folder2/folder2_3/folder2_3_2/

Again in the case of:

!folder2/folder2_3/folder2_3_2/

you have to write

!folder2/folder2_3/folder2_3_2/
!folder2/folder2_3/folder2_3_2/*

and subfolders

!folder2/folder2_3/folder2_3_2/*/*

but it is not enough, because you have to say to not ignore also:

!folder2/
!folder2/folder2_3/
Carlo Bellettini
  • 1,130
  • 11
  • 20