问题
I am using git for a project and want to exclude a specific subfolder from a path but not the siblings of that folder For example:
/Testpath/TestpathA
/Testpath/TestpathB
/Testpath/TestpathC
I want to ignore TestpathA and C (and any other paths that may be siblings of those folders, but not TestpathB
I tried
/Testpath/*
!/Testpath/TestpathB
but that didn't work.
I also tried /Testpath/(?!TestpathB)/*
but that didn't work either.
回答1:
How about;
Testpath/*
!Testpath/TestpathB
Edit: Actually, strike that, your example works just fine for me as well. What exactly is it you are doing that isn't working? Besides creating the .gitignore
, what commands are you running?
回答2:
Using
/Testpath/*
!/Testpath/TestpathB
worked for me:
→ 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
#
来源:https://stackoverflow.com/questions/4809370/how-do-you-do-negative-lookahead-lookbehind-in-the-gitignore-files