我有文件夹应用程序/,我添加到.gitignore。在应用程序/文件夹中是文件夹application/language/gr。我如何包含这个文件夹?
我试过了
application/
!application/language/gr/
我有文件夹应用程序/,我添加到.gitignore。在应用程序/文件夹中是文件夹application/language/gr。我如何包含这个文件夹?
我试过了
application/
!application/language/gr/
当前回答
我想跟踪位于/etc/nagios/中的Nagios配置文件以及/usr/lib64/ Nagios /plugins/中的插件。为此,我在/中初始化了一个git repo,并使用了以下排除列表:
/*
!etc
etc/*
!etc/nagios
!usr
usr/*
!usr/lib64
usr/lib64/*
!usr/lib64/nagios
usr/lib64/nagios/*
!usr/lib64/nagios/plugins
Git像这样遍历列表:
/* exclude everything under / ...
!etc but include /etc back
etc/* exclude everything under /etc/...
!etc/nagios but include /etc/nagios back
!usr but include /usr back
usr/* exclude everything under /usr/...
and so on...
其他回答
我想跟踪jquery生产js文件,这是有效的:
node_modules/*
!node_modules/jquery
node_modules/jquery/*
!node_modules/jquery/dist/*
特别是对于较旧的Git版本,大多数建议都不能很好地工作。 如果是这种情况,我将在我希望包含内容的目录中放置一个单独的.gitignore,而不考虑其他设置,并允许其中包含所需的内容。
例如: / .gitignore
# ignore all .dll files
*.dll
/ dependency_files .gitignore
# include everything
!*
因此,/dependency_files中的所有内容(甚至是.dll文件)都被很好地包含在内。
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
在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/**
对于Git 1.9/2.0(2014年第一季度),Karsten Blees (kblees)的提交59856de澄清了这种情况:
Gitignore.txt:阐明排除目录的递归性质
可选前缀“!”,否定模式;任何被前一个模式排除的匹配文件将被重新包含。 如果排除了文件的父目录,则无法重新包含该文件。(*) (*:除非git 2.8+满足某些条件,见下文) 出于性能原因,Git没有列出排除的目录,因此所包含文件上的任何模式都没有影响,无论它们定义在哪里。 对于以文字“!”开头的模式,在第一个“!”前面加一个反斜杠(“\”),例如,“\!important!.txt”。 示例排除除特定目录foo/bar以外的所有内容(注意/* -没有斜杠,通配符也会排除foo/bar内的所有内容):
--------------------------------------------------------------
$ cat .gitignore
# exclude everything except directory foo/bar
/*
!/foo
/foo/*
!/foo/bar
--------------------------------------------------------------
在你的情况下:
application/*
!application/**/
application/language/*
!application/language/**/
!application/language/gr/**
必须先将文件夹列入白名单,然后才能将给定文件夹中的文件列入白名单。
2016年2月/ 3月更新:
注意,在git 2.9.x/2.10(2016年年中?)中,如果重新包含的路径中没有通配符,则该文件的父目录被排除在外,则可能重新包含该文件。
nguyforgen Thái ngeconc Duy (pclouds)正在尝试添加这个特性:
git v2.7.0提交506d8f1, git v2.8.0-rc0提交76b620d Commit 5e57f9c git v2.8.0-rc0在提交5cee3493 git 2.8.0时被恢复(!)。
因此,在git 2.9+中,这实际上是可以工作的,但最终被恢复了:
application/
!application/language/gr/