Git - 忽略特定文件夹中包含的某些文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/971465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git - Ignore certain files contained in specific folders
提问by
I'm using msysgit and have a project tree that contains many bin/ folders in the tree. Using the .gitignore file in the root of the project I need to ignore all .dll files that reside within a bin/ folder anywhere in the project tree. I've tried "bin/*.dll" but that doesn't work, I assume it is only working against the bin/ folder in the root of the project.
我正在使用 msysgit 并且有一个项目树,其中包含树中的许多 bin/ 文件夹。使用项目根目录中的 .gitignore 文件,我需要忽略驻留在项目树中任意位置的 bin/ 文件夹中的所有 .dll 文件。我试过“bin/*.dll”,但这不起作用,我认为它只适用于项目根目录中的 bin/ 文件夹。
回答by Josef D.
Just had a similar problem and realized: The files were already added and checked in to git.
刚刚遇到了类似的问题并意识到:文件已经添加并签入到 git。
How to recognize the difference: Git didn't show the files as "new", but as "modified". This details has cost me quite some time...
如何识别差异:Git 没有将文件显示为“新的”,而是“修改过的”。这个细节花费了我相当长的时间......
If that is the problem, simply "git rm" these files and start over. Suddenly, .gitignore starts to work as expected.
如果这是问题所在,只需“git rm”这些文件并重新开始。突然,.gitignore 开始按预期工作。
回答by Chetan Sastry
I just have /bin
in my file and it seems to work. It ignore the whole folder (as opposed to specific files in it)
我只是/bin
在我的文件中,它似乎工作。它忽略整个文件夹(而不是其中的特定文件)
Here are the complete contents as of now (still evolving).
以下是截至目前(仍在发展中)的完整内容。
.svn*
obj/
bin/
*.suo
*.user
Log/
log/
*.db
回答by VonC
Update August 2016 (seven years later, Git 2.9.3/ Git 2.10)
2016 年 8 月更新(七年后,Git 2.9.3/Git 2.10)
**/bin/*.dll
That does work for any depth.
这对任何深度都有效。
Original answer (2009, Git 1.6)
原始答案(2009,Git 1.6)
Did you try:
你试过了吗:
**/bin/*.dll
It does work with my msysgit1.6.3 (with a .gitignore
file at the root directory of the Git workspace).
它确实适用于我的 msysgit1.6.3(.gitignore
在 Git 工作区的根目录中有一个文件)。
Actually the above would only ignore 'x/bin/z.dll
', not 'x/y/bin/z.dll
'.
其实上面只会忽略' x/bin/z.dll
',而不是' x/y/bin/z.dll
'。
Another syntax could be:
另一种语法可能是:
**/*/bin/*.dll
But that would only get depth 3, not depth 2!
但这只会得到深度 3,而不是深度 2!
So if you do not have too many place where *.dll need to be ignored, the simplest solution would still be a local .gitignore file in those 'bin' directories...
因此,如果您没有太多需要忽略 *.dll 的地方,最简单的解决方案仍然是那些“bin”目录中的本地 .gitignore 文件...
Or a collection of directive to cover the main first depths:
或者一组指令来覆盖主要的第一个深度:
bin/*.dll
**/bin/*.dll
**/*/bin/*.dll
**/**/*/bin/*.dll
and so on, all in one .gitignore file.
等等,都在一个 .gitignore 文件中。
回答by Coffee_fan
.gitignore on windows, just does not seem to work. I am using msysgit v 1.7.6 beta, and it just does not work the way it should per the .gitignor man page. Now, if I copy the contents of my .gitignore file to the $GIT_DIR/info/exclude file, inside the repo, things do work.
.gitignore 在 Windows 上,似乎不起作用。我正在使用 msysgit v 1.7.6 测试版,但它无法按照 .gitignor 手册页应有的方式工作。现在,如果我将我的 .gitignore 文件的内容复制到 $GIT_DIR/info/exclude 文件,在 repo 中,事情会起作用。
So, the bummer is that this does not get replicated, but it is better than nothing.
因此,令人遗憾的是,这不会被复制,但总比没有好。
回答by 027
Depending on language you are using, you can choose it from link
根据您使用的语言,您可以从链接中选择
For example, If you are using java, you can use gitignore
例如,如果您使用的是 java,则可以使用gitignore
Also https://www.gitignore.io/allows you to create gitingore file online, you just need to enter operating system, IDE or programming language and based on it, It will give you gitignore file. Using it you can create gitignore file for your project easily.
另外https://www.gitignore.io/允许你在线创建 gitingore 文件,你只需要输入操作系统、IDE 或编程语言并基于它,它会给你 gitignore 文件。使用它您可以轻松地为您的项目创建 gitignore 文件。
回答by rball
*/bin worked for me
*/bin 对我来说有效
I'd think that */bin/ would as well.
我认为 */bin/ 也会。