我有文件夹应用程序/,我添加到.gitignore。在应用程序/文件夹中是文件夹application/language/gr。我如何包含这个文件夹?
我试过了
application/
!application/language/gr/
我有文件夹应用程序/,我添加到.gitignore。在应用程序/文件夹中是文件夹application/language/gr。我如何包含这个文件夹?
我试过了
application/
!application/language/gr/
当前回答
我经常在CLI中使用这个解决方案,而不是配置我的.gitignore,我创建了一个单独的.include文件,在其中定义我想包含的(子)目录,尽管目录直接或递归被.gitignore忽略。
因此,我额外使用
git add `cat .include`
在登台期间,提交之前。
对于OP,我建议使用.include,其中包含这些行:
<parent_folder_path>/application/language/gr/*
注意:使用cat不允许使用别名(在.include内)来指定$HOME(或任何其他特定目录)。这是因为行homedir/app1/* 当使用上述命令传递给git add时,显示为git add 'homedir/app1/*',并且将字符括在单引号(")中保留了引号内每个字符的文字值,从而防止别名(如homedir)发挥作用(参见Bash单引号)。
下面是我在这里的repo中使用的.include文件的示例。
/home/abhirup/token.txt
/home/abhirup/.include
/home/abhirup/.vim/*
/home/abhirup/.viminfo
/home/abhirup/.bashrc
/home/abhirup/.vimrc
/home/abhirup/.condarc
其他回答
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_modules/*
!**/node_modules/keep-dir
因为很多程序员使用node。满足这个问题的用例是排除node_modules,除了一个模块module-a,例如:
!node_modules/
node_modules/*
!node_modules/module-a/
特别是对于较旧的Git版本,大多数建议都不能很好地工作。 如果是这种情况,我将在我希望包含内容的目录中放置一个单独的.gitignore,而不考虑其他设置,并允许其中包含所需的内容。
例如: / .gitignore
# ignore all .dll files
*.dll
/ dependency_files .gitignore
# include everything
!*
因此,/dependency_files中的所有内容(甚至是.dll文件)都被很好地包含在内。
关于这个问题还有很多类似的问题,所以我会把我之前写过的贴出来:
我让这个在我的机器上工作的唯一方法是这样做:
# Ignore all directories, and all sub-directories, and it's contents:
*/*
#Now ignore all files in the current directory
#(This fails to ignore files without a ".", for example
#'file.txt' works, but
#'file' doesn't):
*.*
#Only Include these specific directories and subdirectories:
!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,我仍然需要拼写出来。
这是@Yarin的评论:https://stackoverflow.com/a/5250314/1696153
这些都是有用的话题:
负模式在。gitignore中是如何工作的? gitignore排除规则实际上是如何工作的?
我也试过
*
*/*
**/**
和* * / wp-content /主题/ * *
或/ wp-content /主题/ * * / *
这些对我也没用。大量的试验和错误!