2011-09-02 118 views
4

我有文件夹,像这样:的.gitignore排除与文件夹,但包括子目录

/foo/one.txt 
/foo/bar/two.txt 
/foo/other/three.txt 

我想排除在文件夹/富/以外的所有子文件夹/富/酒吧/。我怎么做?

有了这个.gitignore我设法排除“其他”子文件夹,但文件“one.txt”仍然包括在内。

/foo/* 
!/foo/bar/ 
+1

你做了什么工作,你想为我工作。 –

回答

0

这可能是因为当.gitignore现在的工作,你是从需要删除跟踪的常见问题的痛苦文件来自现在在gitignore中的索引,例如why-git-doesnt-ignore-my-specified-file

也就是说,使用git rm <file>删除/确保它不在索引中。

+0

谢谢。它在索引中。愚蠢的我没有真正检查我自己的例子:) – esbite

0

像查尔斯·贝利在评论区说,你的代码工作:

$ cat .gitignore 
/foo/* 
!/foo/bar/ 

$ git status 
# On branch master 
# 
# Initial commit 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# .gitignore 
# foo/ 
nothing added to commit but untracked files present (use "git add" to track) 
$ git add foo/ -n 
add 'foo/bar/two.txt' 
$ 
相关问题