2014-12-03 159 views
0

基本上,我有以下文件夹结构:的.gitignore不能忽略的所有文件夹除外

repo 
    README.md 
    testing_folder 
      readingme.md 
    resources_folder 
.gitignore file

而且,我想忽略除当前目录下的文件夹的所有文件,这是什么我有:

* 
!.gitignore 
!*/ 

当我做git status,这就是我得到:

On branch master 
Your branch is ahead of 'origin/master' by 1 commit. 
    (use "git push" to publish your local commits) 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

    modified: .gitignore 

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: README.md 

问题是:它没有显示testing_folderresources_folderuntracked。当我尝试做git add testing/readingme.md,我得到了以下错误消息:

The following paths are ignored by one of your .gitignore files: 
testing/readingme.md 
Use -f if you really want to add them. 
fatal: no files added 

我开始变得很困惑,因为我已经看了这么多其他相关的职位。他们似乎工作,但我的工作不起作用。

我试图在.gitignore文件中包括和排除!*/语句,但仍然不显示文件夹为untracked

+0

儿童目录中的文件呢?你是否希望它们被忽略,或只有顶级目录中的文件? – 2014-12-03 20:11:53

+0

涵盖两种情况的答案都很好。 – mynameisJEFF 2014-12-03 20:15:19

回答

2

我已经重新创建你在后显示的目录结构,而当我.gitignore包含:

/* 
!*/                   
!.gitignore 

我也注意到,在第一线为*,而不是/*我有同样的问题,因为你。我猜想,添加/可以让git有足够的上下文来做你想做的事情。随着/*git status回报:

On branch master 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

    modified: .gitignore 

Untracked files: 
    (use "git add <file>..." to include in what will be committed) 

    testing_folder/ 

这种意志,实际上,只跟踪其不在父目录中的文件。 resources_folder未显示的原因是因为git不跟踪空目录。 There are some ways to trick git into tracking empty folders,但它不是默认行为。

+0

我现在有点困惑。那么'/ *'和'*'之间的主要区别是什么?何时使用哪个? – mynameisJEFF 2014-12-03 23:04:03

+0

说实话,我真的不确定为什么'/ *'在'*'不行的时候有效。我认为一般情况下,如果你使用'*',git将非常自由地忽略事情,因为你告诉它只是继续前进而忽视所有事情。使用'/ *'虽然看起来很相似,但明确地不忽略根,这可能会让你对被忽略的东西和包含的东西更加严格。 – 2014-12-04 14:37:34

相关问题