Git - 忽略特定文件夹中包含的某些文件

时间:2023-01-16 21:51:29

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 /文件夹起作用。

6 个解决方案

#1


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开始按预期工作。

#2


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

#3


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(在Git工作区的根目录下有一个.gitignore文件)。

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文件。

#4


.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 beta,它只是按照.gitignor手册页的方式工作。现在,如果我将.gitignore文件的内容复制到$ GIT_DIR / info / exclude文件,在repo中,事情确实有效。

So, the bummer is that this does not get replicated, but it is better than nothing.

所以,糟糕的是,这并没有得到复制,但总比没有好。

#5


*/bin worked for me

* / bin为我工作

I'd think that */bin/ would as well.

我认为* / bin /也会。

#6


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文件。

#1


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开始按预期工作。

#2


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

#3


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(在Git工作区的根目录下有一个.gitignore文件)。

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文件。

#4


.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 beta,它只是按照.gitignor手册页的方式工作。现在,如果我将.gitignore文件的内容复制到$ GIT_DIR / info / exclude文件,在repo中,事情确实有效。

So, the bummer is that this does not get replicated, but it is better than nothing.

所以,糟糕的是,这并没有得到复制,但总比没有好。

#5


*/bin worked for me

* / bin为我工作

I'd think that */bin/ would as well.

我认为* / bin /也会。

#6


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文件。