1

bin只有当它不是文件夹的一部分时,我才会忽略文件夹(在 .gitignore 中) packages。可能吗/?

更新。

我会排除以下情况:

packages/bin
packages/somefolder/bin
etc.
4

1 回答 1

3

您可以在您的.gitignore:

bin/
!packages/bin/
!packages/*/bin/
!packages/*/*/bin/

不幸的是 git 不支持**多个目录级别(或正则表达式匹配)的 glob,因此忽略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)
于 2012-05-03T09:57:56.663 回答