你如何在gitignore文件中做负向Lookahead/Lookbehind?
我使用Git的项目,要排除从路径特定的子文件夹而不是该文件夹的兄弟姐妹例如:你如何在gitignore文件中做负向Lookahead/Lookbehind?
/Testpath/TestpathA
/Testpath/TestpathB
/Testpath/TestpathC
我想忽略TestpathA和C(以及任何其他路径可能是这些文件夹的兄弟姐妹,但不TestpathB
我试图
/Testpath/*
!/Testpath/TestpathB
,但没有奏效。
我一个LSO试图 /Testpath /(?!TestpathB)/ *
但也不能工作。
如何;
Testpath/*
!Testpath/TestpathB
编辑:其实,罢工,你的例子对我来说工作得很好。你到底在做什么,这是行不通的?除了创建.gitignore
,你还在运行什么命令?
@ Nemo157 这似乎工作,问题是我有 !TestPath/TestpathB/* 哪些没有工作,仍然允许整个文件夹被否定 – indigo0086 2011-01-26 20:26:36
使用
/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
#
以及我认为领先的路径是在那里忽略文件夹关闭根目录,而不是递归地向下目录树 – indigo0086 2011-01-26 20:13:43
我改变了你的标签 - gitignores不使用正则表达式;他们使用特定的globbing风味。 – Cascabel 2011-01-27 06:05:14