2011-01-26 58 views
0

我使用Git的項目,要排除從路徑特定的子文件夾而不是該文件夾的兄弟姐妹例如:你如何在gitignore文件中做負向Lookahead/Lookbehind?

/Testpath/TestpathA 
/Testpath/TestpathB 
/Testpath/TestpathC 

我想忽略TestpathA和C(以及任何其他路徑可能是這些文件夾的兄弟姐妹,但不TestpathB

我試圖

/Testpath/* 
!/Testpath/TestpathB 

,但沒有奏效。

我一個LSO試圖 /Testpath /(?!TestpathB)/ *

但也不能工作。

+0

我改變了你的標籤 - gitignores不使用正則表達式;他們使用特定的globbing風味。 – Cascabel 2011-01-27 06:05:14

回答

0

如何;

Testpath/* 
!Testpath/TestpathB 

編輯:其實,罷工,你的例子對我來說工作得很好。你到底在做什麼,這是行不通的?除了創建.gitignore,你還在運行什麼命令?

+0

@ Nemo157 這似乎工作,問題是我有 !TestPath/TestpathB/* 哪些沒有工作,仍然允許整個文件夾被否定 – indigo0086 2011-01-26 20:26:36

0

使用

/Testpath/* 
!/Testpath/TestpathB 

工作對我來說:

→ cat .gitignore 
/Testpath/* 
!/Testpath/TestpathB 

→ tree 
. 
└── Testpath 
    ├── TestpathA 
    │   └── testfile 
    ├── TestpathB 
    │   └── testfile 
    └── TestpathC 
     └── testfile 

4 directories, 3 files 

→ git status 
# On branch master 
# 
# Initial commit 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
#  .gitignore 
#  Testpath/ 
nothing added to commit but untracked files present (use "git add" to track) 

→ git add . 

→ git status 
# On branch master 
# 
# Initial commit 
# 
# Changes to be committed: 
# (use "git rm --cached <file>..." to unstage) 
# 
#  new file: .gitignore 
#  new file: Testpath/TestpathB/testfile 
# 
+0

以及我認爲領先的路徑是在那裏忽略文件夾關閉根目錄,而不是遞歸地向下目錄樹 – indigo0086 2011-01-26 20:13:43