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

爱⌒轻易说出口 提交于 2020-01-22 17:41:08

问题


I'm trying to ignore the bin folder of a web project, but include the .refresh files that are in that bin folder.

Here's what I have in my .gitignore:

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

But this isn't working. What am I doing wrong? I've also tried:

!*.refresh

With the same results.

Update:

Here's the file structure if that helps diagnose this:

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

You can see where our gitignore file is located. We don't want the .dll but we do want the .refresh file.


回答1:


Try doing below:

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

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

Edit for OP's structure:

Then you will have to either

1) Include project1 in the path in your .gitignore:

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

or

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




回答2:


This way not worked for me:

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

I have used the syntax bellow on .gitignore file and worked fine.

Try it:

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



回答3:


I know it's an old post, but I was still having this problem, and using MsysGit 1.8.0, I was not able to use the accepted answer by @manojlds.

It seems the only patterns that exclude all bin folders at any depth are [Bb]in and [Bb]in/. According to the gitignore man page, the one with the trailing slash is most correct, since it will only match directories, and not files named "bin". As soon as I try to add additional levels to the pattern, such as [Bb]in/*, this ceases to match at any depth and becomes relative to the location of the .gitignore file, as per the man page.

Now, assuming that I have a [Bb]in/ entry in my global .gitignore file, the best way I found to unignore a specific pattern of files (like .refresh files) in a specific bin folder is to create another .gitignore file one directory above the bin folder (i.e., the project's directory) and in it place the following entries:

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

Our web site project bin folders never contain sub folders like Debug or Release, but I tested and this still ignores subfolders in the bin folder, as desired.

If I only use the second and third entries, as seemed suggested by the accepted answer, it doesn't work. An intuitive explanation is that the first entry removes this specific bin folder from the global glob, so its contents will be included, then the second entry works as desired since it is relative to the .gitignore file in this case, and the third entry removes the desired patterns from the glob created by the second entry.




回答4:


The following works for me:

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

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




回答5:


Another solution could be to force include .refresh files from the commandline.

git add *.dll.refresh --force

--force
Allow adding otherwise ignored files.

Than you can just exclude everything in the bin folder in your .gitignore file. If you add a new package you have to force include the new .refresh file again.




回答6:


With Roslyn ("Enable latest C# and VB features" for a website project), there will now be a subdirectory inside 'bin' which will have .refresh files you'll need. This gets to be a headache because of git's default behavior that once you exclude a folder, any exceptions within it will never be found (/directory/* vs /directory/**/.)

So we needed bin to be as follows:

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

otherwise the entire roslyn directory would be ignored, and then

!**/*.refresh



来源:https://stackoverflow.com/questions/8176102/gitignore-ignoring-bin-but-including-bin-refresh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!