高级Gitignore
我知道您可以使用*测试*
之类的模式来忽略任何包含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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在 @Ilyabursov的评论上展开,
git
不仅在存储库的根中查找.gitignore
- 它寻找.gitignore
中的文件。因此,如果您有:以及所有这些
.gitignore
文件包含*
,然后运行git add。
在存储库的根部结果:
如您所见,
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:And all those
.gitignore
files contain*
, then runninggit add .
in the root of the repository results in:
As you can see,
git
has ignored everything inFolder B
(and inFolder C
, but since that directory was empty, the.gitignore
fileis no-op; recall that
git
only tracks files, not directories).