白名单和Git中的子目录 [英] Whitelisting and subdirectories in Git
问题描述
*
!*。txt
现在,我在子目录中有一个未跟踪的文本文件 - sub / dir /file.txt
,并且不显示(它被忽略)。但是,显示根目录中的文本文件。
为什么会这样,我该如何解决它?
如果以这种方式尝试,它会失败,因为最终会将结构中的目录列入黑名单。
为了解决这个问题,你想把所有不是目录的东西列入黑名单,而不是你想要提交的文件类型之一,而不是黑名单目录即可。
.gitignore
会执行此操作的文件:
#首先,忽略所有内容
*
#现在,将任何目录白名单
!* /
#所有文件类型你有兴趣。
!*。one
!*。two
!*。etc
在存在 我用来找出答案的信息来自于,除其他外, this (stackoverflow.com)。 I have created a white-list for text files only. Now, I have an untracked text file in a sub-directory - Why is that, and how do I fix it? If you try it that way, it'll fail, because you'll end up blacklisting the directories in your structure. To solve, you want to blacklist everything that is not a directory, and is not one of the file-types you want to commit, while not blacklisting directories. The Tested this in a three-level structure white-listing for Information I used to figure out the answer came from, amongst other things, this (stackoverflow.com). 这篇关于白名单和Git中的子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! *。1的情况下,对
.txt
文件进行三级结构白名单测试, *。two
和 *。three
使用 .gitignore
位于存储库的根目录中 - 适用于我。您不必将 .gitignore
文件添加到结构中的所有目录中。
*
!*.txt
sub/dir/file.txt
, and this is NOT shown (it is ignored). Text files in the root directory are shown, however..gitignore
file that will do this:# First, ignore everything
*
# Now, whitelist anything that's a directory
!*/
# And all the file types you're interested in.
!*.one
!*.two
!*.etc
.txt
files in the presence of *.one
, *.two
and *.three
files using a .gitignore
located in the root directory of the repository - works for me. You won't have to add .gitignore
files to all directories in your structure.