高级Gitignore

发布于 2025-02-08 13:15:41 字数 509 浏览 1 评论 0原文

我知道您可以使用*测试*之类的模式来忽略任何包含Word test test的目录或文件。

但是现在我正在寻找更先进的东西。

|- Folder A
|  |- File A
|  |- File B
|- Folder B
|  |- File C
|  |- File D
|  |- Pro.txt
|- Folder C
|  |- Pro.txt
|- Folder D
   |- File E
   |- File F

我想忽略直接包含pro.txt文件的所有文件夹,例如文件夹b& 文件夹C
我不想仅仅忽略文件,我想忽略整个文件夹(带子文件夹和文件)

文件pro.txt是空的,只是指示我不希望成为哪些文件夹上载在git上,不需要存在。

在您说之前,我无法更改文件夹名称以包含一个特定的单词。

I know you can use a pattern like *test* to ignore any directory or file containing word test.

But now I'm looking for something more advanced.

|- Folder A
|  |- File A
|  |- File B
|- Folder B
|  |- File C
|  |- File D
|  |- Pro.txt
|- Folder C
|  |- Pro.txt
|- Folder D
   |- File E
   |- File F

I want to ignore all folders that directly contain the Pro.txt file like Folder B & Folder C.
I do not want to ignore just the file, I want to ignore the whole folder (with subfolders and files)

The file Pro.txt is empty and just an indicator that which folders I do not wish to be uploaded on git and is not required to exist.

And before you say it, I can not change the folder name to contain a specific word.

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

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

发布评论

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

评论(1

丑丑阿 2025-02-15 13:15:41

要在 @Ilyabursov的评论上展开,git不仅在存储库的根中查找.gitignore - 它寻找.gitignore 中的文件。因此,如果您有:

.
├── Folder A
│   ├── File A
│   └── File B
├── Folder B
│   ├── File C
│   ├── File D
│   └── .gitignore
├── Folder C
│   └── .gitignore
└── Folder D
    ├── File E
    └── File F

以及所有这些.gitignore文件包含*,然后运行git add。
在存储库的根部结果:

$ git status
On branch main

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   Folder A/File A
        new file:   Folder A/File B
        new file:   Folder D/File E
        new file:   Folder D/File F

如您所见,git忽略了文件夹B中的所有内容(在
文件夹C,但是由于该目录为空,因此.gitignore文件
没有;回想一下git仅跟踪文件,而不是目录)。

To expand upon @IlyaBursov's comment, git doesn't just look for .gitignore in the root of your repository -- it looks for a .gitignore file in every directory. So if you have:

.
├── Folder A
│   ├── File A
│   └── File B
├── Folder B
│   ├── File C
│   ├── File D
│   └── .gitignore
├── Folder C
│   └── .gitignore
└── Folder D
    ├── File E
    └── File F

And all those .gitignore files contain *, then running git add .
in the root of the repository results in:

$ git status
On branch main

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   Folder A/File A
        new file:   Folder A/File B
        new file:   Folder D/File E
        new file:   Folder D/File F

As you can see, git has ignored everything in Folder B (and in
Folder C, but since that directory was empty, the .gitignore file
is no-op; recall that git only tracks files, not directories).

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