我有文件夹应用程序/,我添加到.gitignore。在应用程序/文件夹中是文件夹application/language/gr。我如何包含这个文件夹?
我试过了
application/
!application/language/gr/
我有文件夹应用程序/,我添加到.gitignore。在应用程序/文件夹中是文件夹application/language/gr。我如何包含这个文件夹?
我试过了
application/
!application/language/gr/
当前回答
gitignore -指定有意忽略的未跟踪文件。
示例排除除特定目录foo/bar以外的所有内容(注意/* -没有斜杠,通配符也会排除foo/bar内的所有内容):
$ cat .gitignore
# exclude everything except directory foo/bar
/*
!/foo
/foo/*
!/foo/bar
WordPress的另一个例子:
!/wp-content
wp-content/*
!/wp-content/plugins
wp-content/plugins/*
!wp-content/plugins/my-awesome-plugin
更多信息在这里:https://git-scm.com/docs/gitignore
其他回答
因为很多程序员使用node。满足这个问题的用例是排除node_modules,除了一个模块module-a,例如:
!node_modules/
node_modules/*
!node_modules/module-a/
我的JetBrains IntelliJ IDEA .gitignore配置,在那里我需要排除整个。IDEA文件夹除了。IDEA /runConfigurations:
.idea
!.idea/
.idea/*
!.idea/runConfigurations/
参见:https://github.com/daggerok/gitignore-idea-runConfigurations
在WordPress中,这帮助了我:
wp-admin/
wp-includes/
/wp-content/*
!wp-content/plugins/
/wp-content/plugins/*
!/wp-content/plugins/plugin-name/
!/wp-content/plugins/plugin-name/*.*
!/wp-content/plugins/plugin-name/**
最简单也可能是最好的方法是手动添加文件(通常这优先于.gitignore风格的规则):
git add /path/to/module
如果文件已经被忽略,则可能需要-f。您甚至可能希望使用-N意图添加标志,以建议您将添加它们,但不是立即添加。我经常对我还没有准备好的新文件这样做。
这是一个答案的副本张贴在什么很容易是一个重复的QA。我在这里重新发布是为了增加能见度——我发现不搞乱gitignore规则更容易。
特别是对于较旧的Git版本,大多数建议都不能很好地工作。 如果是这种情况,我将在我希望包含内容的目录中放置一个单独的.gitignore,而不考虑其他设置,并允许其中包含所需的内容。
例如: / .gitignore
# ignore all .dll files
*.dll
/ dependency_files .gitignore
# include everything
!*
因此,/dependency_files中的所有内容(甚至是.dll文件)都被很好地包含在内。