How to .gitignore files recursively

六月ゝ 毕业季﹏ 提交于 2019-11-27 11:01:37

问题


I'm trying to avoid the following pattern in my .gitignore file.

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?


回答1:


As of git 1.8.2, this:

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

To gitignore every file and folder under a directory recursively:

MyPrject/WebApp/Scripts/special/**



回答2:


Following gitignore manual page:

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

So, this clearly stands that there is no way to specify a certain amount of directories between two strings, like between special and js.

Nevertheless, you can have a .gitignore file per directory, so maybe in your case the following content

*.js

at the following place

MyPrject/WebApp/Scripts/special/.gitignore

would be sufficient?



来源:https://stackoverflow.com/questions/16550688/how-to-gitignore-files-recursively

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!