将名称中包含句点的文件添加到.gitignore

时间:2013-11-07 17:31:44

标签: git gitignore

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

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

我想排除bin目录。这些目录可以明确添加,但有很多会使这个单调乏味。我也试过使用这两行,但它们都没有工作:

*/bin
[Bb]in

如何指定?

我正在使用Windows 7。

2 个答案:

答案 0 :(得分:2)

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

**/bin/

它会忽略存储库中的所有bin文件夹。来自docs

  

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

答案 1 :(得分: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中的.gitignore重新进行了测试(在清理完第一个之后);相同的结果 - 模式工作并抑制了目录。

git --version报告1.8.3.4 (Apple Git-47)的Mac OS X 10.9(Mavericks)上测试。