本文介绍了全局匹配中的**和*之间的差异(.gitignore)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下目录结构和文件。

  pw-spec / 
| - event_spec.coffee
| - event_spec.js
| - 集成
| ` - 服务
| | - auth_spec.coffee
| | - auth_spec.js
| | - chat_spec.coffee
| | - chat_spec.js
| | - transport_spec.coffee
| ` - transport_spec.js
| - message_spec.coffee
| - message_spec.js
| - pw_spec.coffee
| - pw_spec.js
| - run.coffee
| - run.html
| - run.js
| - service
| | - auth_spec.coffee
| | - auth_spec.js
| | - chat_spec.coffee
| | - chat_spec.js
| | - stream_spec.coffee
| ` - stream_spec.js
| - spec.coffee
| - spec.js
` - 存根
| - stream.coffee
| - - stream.js
| - transport.coffee
` - transport.js

4个目录,27个文件

我想忽略 pw-spec中任何地方的所有 *。js 文件目录。



但是,将以下模式添加到 .gitignore 不会削减它:

  pw-spec / *。js 
pw-spec / ** / *。js

问题是第二个只匹配树中正好是1级
的js文件,而我想匹配 pw-spec 下的所有js文件。



  ls pw-spec / ** / *。js 

生成[1]:

  pw-spec / service / auth_spec.js 
pw -spec / service / chat_spec.js
pw-spec / service / stream_spec.js
pw-spec / stub / stream.js
pw-spec / stub / transport.js

正如您所见

  pw-spec / integration / service / auth_spec.js 
pw-spec / integration / service / chat_spec.js
pw-spec / integration / service / transport_spec.js

缺少[1]。

** 不起作用,至少不适合每个人。见





您可以在<$ $中有一个单独的 .gitignore c $ c> pw-spec /


I have the following directory structure and files.

pw-spec/
|-- event_spec.coffee
|-- event_spec.js
|-- integration
|   `-- service
|       |-- auth_spec.coffee
|       |-- auth_spec.js
|       |-- chat_spec.coffee
|       |-- chat_spec.js
|       |-- transport_spec.coffee
|       `-- transport_spec.js
|-- message_spec.coffee
|-- message_spec.js
|-- pw_spec.coffee
|-- pw_spec.js
|-- run.coffee
|-- run.html
|-- run.js
|-- service
|   |-- auth_spec.coffee
|   |-- auth_spec.js
|   |-- chat_spec.coffee
|   |-- chat_spec.js
|   |-- stream_spec.coffee
|   `-- stream_spec.js
|-- spec.coffee
|-- spec.js
`-- stub
    |-- stream.coffee
    |-- stream.js
    |-- transport.coffee
    `-- transport.js

4 directories, 27 files

I would like to ignore all *.js files anywhere within pw-spec directory.

However, adding the following patterns to .gitignore doesn't cut it:

pw-spec/*.js
pw-spec/**/*.js

The problem is that the second one only matches js files that are exactly 1 leveldeep within the tree, while I want to match all js files under pw-spec.

Doing

ls pw-spec/**/*.js

produces [1]:

pw-spec/service/auth_spec.js
pw-spec/service/chat_spec.js
pw-spec/service/stream_spec.js
pw-spec/stub/stream.js
pw-spec/stub/transport.js

As you can see

pw-spec/integration/service/auth_spec.js
pw-spec/integration/service/chat_spec.js
pw-spec/integration/service/transport_spec.js

are missing from [1].

解决方案

The difference is that ** doesn't work, at least not for everyone. See

Why doesn't gitignore work in this case?

You can have a separate .gitignore in pw-spec/

这篇关于全局匹配中的**和*之间的差异(.gitignore)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 05:30