0

我在为.gitignore文件创建一些条目时遇到问题。有名称中带有的目录.,如下所示:

Thing1.This/bin  
Thing1.That/bin 
Thing1.TheOther/bin  

我想排除 bin 目录。这些目录可以显式添加,但有很多会使这变得乏味。我也尝试使用这两条线,但它们都不起作用:

*/bin
[Bb]in

如何指定?

我正在使用 Windows 7。

4

2 回答 2

2

如果要将bin任何子目录中的目录添加到 gitignore,可以使用以下语法:

**/bin/

它忽略存储库中的所有 bin 文件夹。从文档

前导“ **”后跟斜杠表示在所有目录中都匹配。例如,“ **/foo”在任何地方匹配文件或目录“foo”,与模式“foo”相同。" **/foo/bar" 匹配目录 "foo" 下的任何位置的文件或目录 "bar"。

于 2013-11-07T18:10:20.823 回答
1

我跑了:

$ for number in $(seq 1 9); do mkdir -p Thing$number.Thing/bin; done
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   makefile
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   b+tree
#   b+tree.cpp
#   cswap.c
#   qs.c
#   qs2.c
#   qs3.c
#   select.c
#   shm
#   shm.c
#   sleepers-awake.c
no changes added to commit (use "git add" and/or "git commit -a")
$ 

目录中没有内容,因此没有任何git可跟踪的内容,因此未将它们列为需要跟踪。我将文件添加到目录:

$ for d in Thing?.Thing/bin; do cp qs.c $d; done
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   makefile
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   Thing1.Thing/
#   Thing2.Thing/
#   Thing3.Thing/
#   Thing4.Thing/
#   Thing5.Thing/
#   Thing6.Thing/
#   Thing7.Thing/
#   Thing8.Thing/
#   Thing9.Thing/
#   b+tree
#   b+tree.cpp
#   cswap.c
#   qs.c
#   qs2.c
#   qs3.c
#   select.c
#   shm
#   shm.c
#   sleepers-awake.c
no changes added to commit (use "git add" and/or "git commit -a")
$

目录现在显示git为需要添加。我编辑.gitignore添加Thing*.Thing/bin如下:

Thing*.Thing/bin
*.a
*.dSYM
*.o
*.so
*~
a.out
core
posixver.h
timer.h

我重新运行git status

$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   .gitignore
#   modified:   makefile
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   b+tree
#   b+tree.cpp
#   cswap.c
#   qs.c
#   qs2.c
#   qs3.c
#   select.c
#   shm
#   shm.c
#   sleepers-awake.c
no changes added to commit (use "git add" and/or "git commit -a")
$

因此,可以使正则表达式(globs?)起作用。*/bin我还使用in重新运行了测试(在清理了第一个测试之后).gitignore;同样的结果——该模式起作用并抑制了目录。

在 Mac OS X 10.9 (Mavericks) 上测试,带有git --version报告1.8.3.4 (Apple Git-47)

于 2013-11-07T17:44:12.873 回答