如何在 gitignore 文件中执行负 Lookahead/Lookbehind 操作?

发布于 2024-10-14 10:35:54 字数 354 浏览 6 评论 0原文

我正在将 git 用于项目,并希望从路径中排除特定的子文件夹,但不排除该文件夹的同级文件夹 例如:

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

我想忽略 TestpathA 和 C (以及可能是这些文件夹的同级文件夹的任何其他路径,但不忽略 TestpathB

我尝试过

/Testpath/*
!/Testpath/TestpathB

但没有成功。

, /Testpath/(?!TestpathB)/*

但这也不起作用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半步萧音过轻尘 2024-10-21 10:35:54

怎么样;

Testpath/*
!Testpath/TestpathB

编辑:实际上,请注意,你的例子对我来说也很好。您到底在做什么但不起作用?除了创建 .gitignore 之外,您还运行哪些命令?

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?

无声无音无过去 2024-10-21 10:35:54

使用

/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
#

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
#
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文