我只会忽略bin
文件夹(在.gitignore中),如果它不是packages
文件夹的一部分。是否可能/?
更新
我想排除以下情况:
packages/bin
packages/somefolder/bin
etc.
答案 0 :(得分:3)
您可以在.gitignore
:
bin/
!packages/bin/
!packages/*/bin/
!packages/*/*/bin/
不幸的是,git不支持多个目录级别的**
glob(或regexp匹配),因此要忽略packages/whatever/bin
和packages/whatever/whatever/bin
,您需要两个条目(依此类推,以便进行更深层的嵌套) )。
演示:
[adrian@hades:/tmp/gitignore:master]> git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# foo/bar/bin/
# foo/baz/bin/
# packages/bin/
# packages/xxx/bin/
# packages/xxx/yyy/bin/
# xxx/packages/bin/
nothing added to commit but untracked files present (use "git add" to track)
[adrian@hades:/tmp/gitignore:master]> cat > .gitignore
bin/
!packages/bin/
!packages/*/bin/
!packages/*/*/bin/
[adrian@hades:/tmp/gitignore:master]> git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# packages/bin/
# packages/xxx/bin/
# packages/xxx/yyy/bin/
nothing added to commit but untracked files present (use "git add" to track)