白名单和Git中的子目录 [英] Whitelisting and subdirectories in Git

查看:121
本文介绍了白名单和Git中的子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只为文本文件创建了一个白名单。

  * 
!*。txt

现在,我在子目录中有一个未跟踪的文本文件 - sub / dir /file.txt ,并且不显示(它被忽略)。但是,显示根目录中的文本文件。



为什么会这样,我该如何解决它?

解决方案

如果以这种方式尝试,它会失败,因为最终会将结构中的目录列入黑名单。



为了解决这个问题,你想把所有不是目录的东西列入黑名单,而不是你想要提交的文件类型之一,而不是黑名单目录即可。



.gitignore 会执行此操作的文件:

 #首先,忽略所有内容
*
#现在,将任何目录白名单
!* /
#所有文件类型你有兴趣。
!*。one
!*。two
!*。etc

在存在 *。1的情况下,对 .txt 文件进行三级结构白名单测试, *。two *。three 使用 .gitignore 位于存储库的根目录中 - 适用于我。您不必将 .gitignore 文件添加到结构中的所有目录中。

我用来找出答案的信息来自于,除其他外, this (stackoverflow.com)。


I have created a white-list for text files only.

*
!*.txt

Now, I have an untracked text file in a sub-directory - sub/dir/file.txt, and this is NOT shown (it is ignored). Text files in the root directory are shown, however.

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 .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

Tested this in a three-level structure white-listing for .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.

Information I used to figure out the answer came from, amongst other things, this (stackoverflow.com).

这篇关于白名单和Git中的子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆