.gitignore中,不是`**`才代表任意目录下吗,为何这样也被匹配了呢?

请问一下,我有一个测试的git项目:
/Git-Test/
在此目录下有.gitignore 文件:

/Git-Test/.gitignore

在下面有多个测试项目,比如:

/Git-Test/react-test/react-proj-01/
/Git-Test/react-test/react-proj-01/

/Git-Test/flutter-test/flutter-proj-01/
/Git-Test/flutter-test/flutter-proj-02/

我的/Git-Test/.gitignore文件为:


### Flutter ###
# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.fvm/flutter_sdk
.packages
.pub-cache/
.pub/
build/
coverage/
lib/generated_plugin_registrant.dart
# For library packages, don’t commit the pubspec.lock file.
# Regenerating the pubspec.lock file lets you test your package against the latest compatible versions of its dependencies.
# See https://dart.dev/guides/libraries/private-files#pubspeclock
#pubspec.lock

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/key.properties
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/.last_build_id
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

###

请见,比如里面的配置:build/ ,是指的/Git-Test/此目录下的build/没错吧,
但是我commit 提交公共库之后,在如下目录下:

/Git-Test/flutter-test/flutter-proj-01/
/Git-Test/flutter-test/flutter-proj-02/

build/都是没有被追踪的。
当然这个不被追踪肯定是好的,但是是什么原理导致不被追踪的呢,不是**才代表任意目录下吗?

阅读 1.5k
2 个回答

https://git-scm.com/docs/gitignore

The slash "/" is used as the directory separator. Separators may occur at the beginning, middle or end of the .gitignore search pattern.

If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level.

build/ ,不是指的/Git-Test/此目录下的build/, 是递归的任意文件夹下的 build。
例证 - 开源开发库 Vue .gitignore 如下,

image.png

node_modules 或忽略子目录中的 node_modules

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏