GitIgnore - Ignoring bin / but including bin / *. Refresh

I am trying to ignore the bin folder in a web project, but am including the .refresh files that are in that bin folder.

Here is what I have in my .gitignore:

[Bb]in/ #Allow .refresh files for web sites ![Bb]in/*.refresh 

But that does not work. What am I doing wrong? I also tried:

 !*.refresh 

With the same results.

Update:

Here is the file structure if it helps diagnose this:

 \rootfolder .gitignore \project1 \bin file1.dll file1.dll.refresh 

You can see where our gitignore file is located. We do not want a .dll, but we need a .refresh file.

+7
source share
6 answers

Try the following:

 [Bb]in/* ![Bb]in/*.refresh 

this is because when you just do bin or bin /, it will not go into the folder at all to search for the file. You will need to directly say, go to the folder, but ignore everything, and then say, do not ignore * .refresh.

Edit for OP structure:

Then you have to either

1) Include project1 in the path in .gitignore :

 project1/bin/* project1/bin/*.refresh 

or

2) Add .gitignore inside project1 (I recommend this) with the previous content.

+7
source

I know this old post, but I still had this problem, and using MsysGit 1.8.0 I was not able to use the accepted @manojlds answer.

It seems that the only templates that exclude all bin folders at any depth are [Bb]in and [Bb]in/ . According to the gitignore man page, the one that has a trailing slash is the most correct, since it will only match directories, not files named "bin", As soon as I try to add additional levels to the template, for example [Bb]in/* , it stops matching at any depth and becomes relative to the location of the .gitignore file, as on the manual page.

Now, assuming I have an [Bb]in/ entry in my global .gitignore file, the best way I found to not write a separate file template (e.g. .refresh files) in a separate bin folder is to create another .gitignore create one directory above the bin folder (i.e. the project directory) and paste the following entries:

 ![Bb]in/ [Bb]in/* ![Bb]in/*.refresh 

Our folders with the folders of the website project never contain subfolders such as Debug or Release, but I tested them and it still ignores the subfolders in the bin folder if necessary.

If I use only the second and third entries, as suggested by the accepted answer, this will not work. An intuitive explanation is that the first record deletes this particular bin folder from the global globe, so its contents will be included, then the second record will work as desired, since in this case it refers to the .gitignore file, and the third record deletes the necessary templates from globe created by the second entry.

+4
source

This method did not work for me:

 [Bb]in/* ![Bb]in/*.refresh 

I used the syntax below in the .gitignore file and worked fine.

Try:

 **/[Bb]in/* !**/[Bb]in/*.refresh 
+4
source

The following works for me:

 [Bb]in/* ![Bb]in/*.refresh 

Note that the first line received a trailing asterisk to match the entire contents of the bin directory, not the directory itself. This way you can add an exception from glob for * .refresh.

+3
source

Another solution might be to force the inclusion of .refresh files from the command line.

git add *.dll.refresh --force

- force
Allow adding ignored files.

Than you can just exclude everything in the bin folder in your .gitignore file. If you add a new package that you must force to enable, re-enable the new .refresh file.

+1
source

With Roslyn ("Enable the latest C # and VB features" for a website project), there will now be a subdirectory inside "bin" in which they will have the necessary .refresh files. This becomes a headache due to the default git behavior, which when you exclude a folder, any exceptions inside it will never be found (/ directory / * vs / directory / ** /.)

So, we needed the following:

**/[Bb]in/**/*.*

otherwise the entire roslyn directory will be ignored and then

!**/*.refresh

0
source

All Articles