How do you do negative Lookahead/Lookbehind in the gitignore files?

倖福魔咒の 提交于 2019-12-25 06:24:02

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!