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

发布于 2024-07-24 08:47:16 字数 161 浏览 8 评论 0原文

我正在使用 msysgit 并有一个项目树,其中包含树中的许多 bin/文件夹。 使用项目根目录中的 .gitignore 文件,我需要忽略项目树中任何位置的 bin/ 文件夹中驻留的所有 .dll 文件。 我尝试过“bin/*.dll”,但这不起作用,我认为它仅适用于项目根目录中的 bin/ 文件夹。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

我是男神闪亮亮 2024-07-31 08:47:16

刚刚遇到了类似的问题并意识到:文件已经添加并签入到 git 中。

如何识别差异:Git 不会将文件显示为“新”,而是显示为“已修改”。 这个细节花了我相当长的时间......

如果这是问题所在,只需“git rm”这些文件并重新开始。 突然,.gitignore 开始按预期工作。

Just had a similar problem and realized: The files were already added and checked in to 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...

If that is the problem, simply "git rm" these files and start over. Suddenly, .gitignore starts to work as expected.

最丧也最甜 2024-07-31 08:47:16

2016 年 8 月更新(七年后,Git 2.9.3/ Git 2.10)

**/bin/*.dll

这适用于任何深度。


原始答案(2009,Git 1.6)

您尝试过吗:

**/bin/*.dll

它确实适用于我的 msysgit1.6.3 (在 Git 工作区的根目录中有一个 .gitignore 文件)。

实际上上面只会忽略'x/bin/z.dll',而不是'x/y/bin/z.dll'。

另一种语法可能是:

**/*/bin/*.dll

但这只能得到深度 3,而不是深度 2!

因此,如果您没有太多需要忽略 *.dll 的地方,最简单的解决方案仍然是这些“bin”目录中的本地 .gitignore 文件...

或者覆盖主要第一个深度的指令集合:

bin/*.dll
**/bin/*.dll
**/*/bin/*.dll
**/**/*/bin/*.dll

等等,全部都在一个 .gitignore 文件中。

Update August 2016 (seven years later, Git 2.9.3/ Git 2.10)

**/bin/*.dll

That does work for any depth.


Original answer (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).

Actually the above would only ignore 'x/bin/z.dll', not 'x/y/bin/z.dll'.

Another syntax could be:

**/*/bin/*.dll

But that would only get depth 3, not depth 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...

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.

惯饮孤独 2024-07-31 08:47:16

我的文件中只有 /bin ,它似乎可以工作。 它忽略整个文件夹(而不是其中的特定文件)

以下是到目前为止的完整内容(仍在发展中)。

.svn*
obj/
bin/
*.suo
*.user
Log/
log/
*.db

I just have /bin in my file and it seems to work. It ignore the whole folder (as opposed to specific files in it)

Here are the complete contents as of now (still evolving).

.svn*
obj/
bin/
*.suo
*.user
Log/
log/
*.db
我早已燃尽 2024-07-31 08:47:16

.gitignore 在 Windows 上似乎不起作用。 我正在使用 msysgit v 1.7.6 beta,它只是无法按照 .gitignor 手册页应有的方式工作。 现在,如果我将 .gitignore 文件的内容复制到存储库内的 $GIT_DIR/info/exclude 文件中,一切就可以正常工作了。

所以,令人遗憾的是,这没有被复制,但总比没有好。

.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.

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

刘备忘录 2024-07-31 08:47:16

根据您使用的语言,您可以从链接中进行选择,

例如,如果您使用的是java,您可以使用 gitignore

https://www.gitignore.io/ 允许您在线创建gitingore文件,您只需要进入操作系统、IDE或编程语言并基于就可以了,它会给你 gitignore 文件。 使用它您可以轻松地为您的项目创建 gitignore 文件。

Depending on language you are using, you can choose it from link

For example, If you are using java, you can use 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.

秋凉 2024-07-31 08:47:16

*/bin 为我工作,

我认为 */bin/ 也会。

*/bin worked for me

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文