GitIgnore - 忽略 bin/ 但包括 bin/*.refresh
我试图忽略 Web 项目的 bin 文件夹,但包含该 bin 文件夹中的 .refresh 文件。
这是我的 .gitignore 中的内容:
[Bb]in/
#Allow .refresh files for web sites
![Bb]in/*.refresh
但这不起作用。我做错了什么?我也尝试过:
!*.refresh
结果相同。
更新:
以下是文件结构(如果有助于诊断此问题):
\rootfolder
.gitignore
\project1
\bin
file1.dll
file1.dll.refresh
您可以看到我们的 gitignore 文件所在的位置。我们不需要 .dll,但我们确实需要 .refresh 文件。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这种方式对我不起作用:
我在 .gitignore 文件上使用了以下语法并且工作正常。
尝试一下:
This way not worked for me:
I have used the syntax bellow on .gitignore file and worked fine.
Try it:
尝试执行以下操作:
这是因为当您只执行 bin 或 bin/ 时,它根本不会下降到文件夹中查找文件。您必须明确地说,转到文件夹,但忽略所有内容,然后说不要忽略 *.refresh。
编辑OP的结构:
然后你必须
1)在.gitignore的路径中包含project1:
或
2)在project1内添加.gitignore(我推荐这个) 与之前的内容。
Try doing below:
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:
or
2) Add a .gitignore inside project1 ( I recommend this) with the previous content.
我知道这是一篇旧帖子,但我仍然遇到这个问题,并且使用 MsysGit 1.8.0,我无法使用 @manojlds 接受的答案。
似乎排除任何深度的所有 bin 文件夹的唯一模式是
[Bb]in
和[Bb]in/
。根据 gitignore 手册页,带有尾部斜杠的那个是最正确的,因为它只会匹配目录,而不是名为“bin”的文件。一旦我尝试向模式添加其他级别,例如[Bb]in/*
,它就会停止在任何深度匹配,并变得相对于 .gitignore 文件的位置,根据手册页。现在,假设我的全局 .gitignore 文件中有一个
[Bb]in/
条目,这是我发现忽略特定 bin 文件夹中的特定文件模式(例如 .refresh 文件)的最佳方法的方法是在 bin 文件夹(即项目目录)上方的一个目录中创建另一个 .gitignore 文件,并在其中放置以下条目:我们的网站项目 bin 文件夹从不包含 Debug 或 Release 等子文件夹,但我测试过,这仍然忽略bin 文件夹中的子文件夹(根据需要)。
如果我只使用第二个和第三个条目,正如已接受的答案所建议的那样,它不起作用。直观的解释是,第一个条目从全局 glob 中删除此特定 bin 文件夹,因此将包含其内容,然后第二个条目按预期工作,因为在本例中它是相对于 .gitignore 文件,而第三个条目则删除第二个条目创建的 glob 中所需的模式。
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: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.
使用 Roslyn(为网站项目“启用最新的 C# 和 VB 功能”),“bin”内现在将有一个子目录,其中包含您需要的 .refresh 文件。这会让人头疼,因为 git 的默认行为是,一旦排除某个文件夹,就永远不会发现其中的任何异常(/directory/* 与 /directory/**/.),
因此我们需要bin 如下:
**/[Bb]in/**/*.*
否则整个 roslyn 目录将被忽略,然后
!**/*.refresh
代码>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
以下对我有用:
请注意,第一行末尾有一个星号来匹配 bin 目录的所有内容,而不是目录本身。通过这种方式,您可以从 glob 中为 *.refresh 添加异常。
The following works for me:
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.
另一个解决方案可能是从命令行强制包含 .refresh 文件。
git add *.dll.refresh --force
您可以排除 .gitignore 文件中 bin 文件夹中的所有内容。
如果添加新包,则必须再次强制包含新的 .refresh 文件。
Another solution could be to force include .refresh files from the commandline.
git add *.dll.refresh --force
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.