忽略 git 项目上的任何“bin"目录 [英] ignoring any 'bin' directory on a git project

查看:57
本文介绍了忽略 git 项目上的任何“bin"目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的目录结构:

.git/
.gitignore
main/
  ...
tools/
  ...
...

在 main 和 tools 以及任何其他目录中,在任何级别,都可以有一个bin"目录,我想忽略它(我也想忽略它下面的所有内容).我已经在 .gitignore 中尝试了这些模式中的每一个,但没有一个工作:

Inside main and tools, and any other directory, at any level, there can be a 'bin' directory, which I want to ignore (and I want to ignore everything under it too). I've tried each of these patterns in .gitignore but none of them work:

/**/bin/**/*
/./**/bin/**/*
./**/bin/**/*
**/bin/**/*
*/bin/**/*
bin/**/*
/**/bin/* #and the others with just * at the end too

谁能帮帮我?如果我这样做,第一个模式(我认为应该工作的模式)工作得很好:

Can anyone help me out? The first pattern (the one I think should be working) works just fine if I do this:

/main/**/bin/**/*

但我不想为每个顶级目录都有一个条目,我不想每次添加新目录时都必须修改 .gitignore.

But I don't want to have an entry for every top-level directory and I don't want to have to modify .gitignore every time I add a new one.

这是在 Windows 上使用最新的 msysgit.

This is on Windows using the latest msysgit.

还有一件事,有些文件和目录的名称中包含子字符串bin",我不希望它们被忽略:)

推荐答案

在 1.8.2 版本之前,**.gitignore 中没有任何特殊含义.从 1.8.2 开始,git 支持 ** 表示零个或多个子目录(参见 发行说明).

Before version 1.8.2, ** didn't have any special meaning in the .gitignore. As of 1.8.2 git supports ** to mean zero or more sub-directories (see release notes).

忽略目录树中当前级别以下任何位置的所有名为 bin 的目录的方法是使用具有以下模式的 .gitignore 文件:

The way to ignore all directories called bin anywhere below the current level in a directory tree is with a .gitignore file with the pattern:

bin/

man 页面中,有一个使用类似模式忽略名为foo 的目录的示例.

In the man page, there an example of ignoring a directory called foo using an analogous pattern.

如果您的 git 索引中已经有任何您不再希望跟踪的 bin 文件夹,那么您需要明确删除它们.Git 不会仅仅因为它们现在匹配新的 .gitignore 模式而停止跟踪已经被跟踪的路径.仅以递归方式 (-r) 从索引 (--cached) 中执行文件夹删除 (rm).根 bin 文件夹的命令行示例:

If you already have any bin folders in your git index which you no longer wish to track then you need to remove them explicitly. Git won't stop tracking paths that are already being tracked just because they now match a new .gitignore pattern. Execute a folder remove (rm) from index only (--cached) recursivelly (-r). Command line example for root bin folder:

git rm -r --cached bin

这篇关于忽略 git 项目上的任何“bin"目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆