gpt4 book ai didi

git - 使用 .gitignore 忽略特定目录以外的所有内容

转载 作者:IT王子 更新时间:2023-10-29 01:22:01 25 4
gpt4 key购买 nike

我的问题是我的 git 存储库中有一堆 WordPress 网站,我想有选择地只提交我的 themes 文件夹的内容,同时忽略找到的其余冗余文件在 WordPress 中。

我以前使用 .gitignore 文件来忽略文件类型,但它能以相反的方式使用吗 - 即忽略除特定文件夹路径之外的所有内容?

root (git repo)
- / wordpress
- - / (WordPress Site 1)/wp-content/themes
- - / (WordPress Site 2)/wp-content/themes
- - / (WordPress Site 3)/wp-content/themes

谢谢-

更新:

根据我的回答,我做了以下操作,但没有用。有什么想法吗?

# Ignore everything:
*
# Except for wordpress themes:
!*/wp-content/themes/*

我还尝试了以下变体:

!*/wp-content/themes*
!*wp-content/themes/*
!wp-content/themes/*
!/wordpress/*/wp-content/themes*
!wordpress/*/wp-content/themes*

这些都不会读取我的 themes 文件夹。

最佳答案

我是这样做的——你基本上必须沿着路径走,你不能在任何方向通配超过一个级别:

# Ignore everything:
*

# Except for the themes directories:

!wordpress/
!wordpress/*/
!wordpress/*/wp-content/
!wordpress/*/wp-content/themes/
!wordpress/*/wp-content/themes/*
!wordpress/*/wp-content/themes/*/*
!wordpress/*/wp-content/themes/*/*/*
!wordpress/*/wp-content/themes/*/*/*/*
!wordpress/*/wp-content/themes/*/*/*/*/*

请注意您必须如何明确允许要包含的每个级别的内容。因此,如果我在主题下有 5 个子目录,我仍然需要将其拼写出来。

这只是它对我有用的方式。如果有人愿意通过各种方式提供更明智的解释。

此外,这些答案很有帮助:
how-do-negated-patterns-work-in-gitignore
how-do-gitignore-exclusion-rules-actually-work


注意:我尝试使用双通配符“globs”,但根据 this该功能取决于系统,在我的 Mac 上不起作用:

无效:

!**/wp-content/themes/
!**/wp-content/themes/**

关于git - 使用 .gitignore 忽略特定目录以外的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5241644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com