2011-09-02 128 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' 
$ 
相關問題