我有文件夹应用程序/,我添加到.gitignore。在应用程序/文件夹中是文件夹application/language/gr。我如何包含这个文件夹?

我试过了

application/
!application/language/gr/

当前回答

在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/**

其他回答

我的JetBrains IntelliJ IDEA .gitignore配置,在那里我需要排除整个。IDEA文件夹除了。IDEA /runConfigurations:

.idea
!.idea/
.idea/*
!.idea/runConfigurations/

参见:https://github.com/daggerok/gitignore-idea-runConfigurations

添加一个额外的答案:

!/.vs/              <== include this folder to source control, folder only, nothing else
/.vs/*              <== but ignore all files and sub-folder inside this folder
!/.vs/ProjectSettings.json <== but include this file to source control
!/.vs/config/       <== then include this folder to source control, folder only, nothing else
!/.vs/config/*      <== then include all files inside the folder

结果如下:

我经常在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

在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/**

我想跟踪位于/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...