git 如何递归.gitignore文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16550688/
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
How to .gitignore files recursively
提问by orad
I'm trying to avoid the following pattern in my .gitignore
file.
我试图在我的.gitignore
文件中避免以下模式。
MyPrject/WebApp/Scripts/special/*.js
MyPrject/WebApp/Scripts/special/*/*.js
MyPrject/WebApp/Scripts/special/*/*/*.js
MyPrject/WebApp/Scripts/special/*/*/*/*.js
MyPrject/WebApp/Scripts/special/*/*/*/*/*.js
MyPrject/WebApp/Scripts/special/*/*/*/*/*/*.js
MyPrject/WebApp/Scripts/special/*/*/*/*/*/*/*.js
We tried:
我们尝试了:
MyPrject/WebApp/Scripts/special/**.js
MyPrject/WebApp/Scripts/special/**/*.js
This however didn't work. This is git on Windows. Is there a more concise way to do this without repeating things?
然而这并没有奏效。这是 Windows 上的 git。有没有更简洁的方法来做到这一点而不重复?
回答by Sam
As of git 1.8.2, this:
从 git 1.8.2 开始,这个:
MyPrject/WebApp/Scripts/special/**/*.js
Should work according to this answer. It also works for me in Windows 7 using Sourcetree 1.6.12.0 and the version of git that it installs (1.8.4-preview20130916).
应该根据这个答案工作。它也适用于我在 Windows 7 中使用 Sourcetree 1.6.12.0 和它安装的 git 版本 (1.8.4-preview20130916)。
To gitignore every file and folder under a directory recursively:
要递归地 gitignore 目录下的每个文件和文件夹:
MyPrject/WebApp/Scripts/special/**
回答by Guillaume Lema?tre
Following gitignore manual page:
以下 gitignore 手册页:
[...] git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname.
[...] git 将模式视为适合 fnmatch(3) 使用 FNM_PATHNAME 标志的 shell glob:模式中的通配符将与路径名中的 / 不匹配。
So, this clearly stands that there is no way to specify a certain amount of directoriesbetween two strings, like between special
and js
.
因此,这显然表明无法在两个字符串之间指定一定数量的目录,例如 betweenspecial
和js
。
Nevertheless, you can have a .gitignore
file per directory, so maybe in your case the following content
尽管如此,您可以为.gitignore
每个目录创建一个文件,因此在您的情况下可能包含以下内容
*.js
at the following place
在以下地方
MyPrject/WebApp/Scripts/special/.gitignore
would be sufficient?
就足够了吗?
回答by Jonathan
This works for me in on osx.
这在 osx 上对我有用。
lib64/**/__pycache__/
lib/**/__pycache__/
*.py[cod]
.ipynb_checkpoints/
**/.ipynb_checkpoints/
.DS_Store
**/.DS_Store
回答by Pradipta Sarma
Try executing git rm -r --cached MyPrject/WebApp/Scripts/special/
Your mentioned directory might have been cached by git and will show up on untracked files.
After clearing the cache make sure you have it mentioned on .gitignore
.
尝试执行git rm -r --cached MyPrject/WebApp/Scripts/special/
您提到的目录可能已被 git 缓存,并将显示在未跟踪的文件中。清除缓存后,请确保在.gitignore
.