.gitignore语法:bin vs bin / vs bin / * vs bin / ** [英] .gitignore Syntax: bin vs bin/ vs. bin/* vs. bin/**

查看:106
本文介绍了.gitignore语法:bin vs bin / vs bin / * vs bin / **的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

添加 bin bin / bin / * bin / ** 在我的.gitignore文件中?我一直在使用 bin / ,但看着其他 .gitignore文件(位于 eclipse文件,双星和单星甚至可以像这样一起使用: tmp / ** / * 这是怎么回事?)我发现前两种模式也被广泛使用。有人可以解释三者之间的区别吗? 或目录。

bin / 匹配任何目录命名为'bin',这实际上意味着它的所有内容,因为Git不会单独跟踪目录。

bin / * 直接匹配任何 bin / 中的所有文件和目录。这会阻止Git自动在其子目录中找到任何文件,但是如果创建了 bin / foo 子目录,则此规则将匹配 foo 的内容。



bin / ** 文件和目录在任何 bin / 目录及其所有子目录中。 因为规则与文件系统根目录不相关,并且在文件系统树中的任意位置应用 。您必须以 / (或!/ 取消忽略)开始规则,这意味着存储库的根,而不是系统的根目录,以仅匹配预期内容。



警告:您应永不使用像 dir / * / dir / ** ,等等,除非您还忽略了一些存在的东西在该目录内。省略星号或,这些数据来自某些调用 git gc git stash 等等。



我真的不知道 tmp / ** / * 是为了做。我最初认为它可以用来匹配 tmp / 子目录中的文件,但不能直接存在于 tmp / tmp / 中的所有文件。


What's the difference between adding bin, bin/, bin/* and bin/** in my .gitignore file? I've been using bin/, but looking at other .gitignore files (in the eclipse file the double and single star are even used together like this: tmp/**/* what's up with that?) I see that the first two patterns are also widely used as well. Can someone please explain the differences between the three?

解决方案

bin matches any files or directories named 'bin'.

bin/ matches any directories named 'bin', which in effect means all of its contents since Git doesn't track directories alone.

bin/* matches all files and directories directly in any bin/. This prevents Git automatically finding any files in its subdirectories, but if, say a bin/foo subdirectory is created, this rule will not match foo's contents.

bin/** matches all files and directories in any bin/ directory and all of its subdirectories.

The word "any" is critical here since rules are not relative to the repository root and apply anywhere in the filesystem tree. You must begin rules with a / (or !/ to un-ignore) which means the repository's root, not the system's root, in order to match only what was intended.

WARNING: You should never use rules like dir/*, /dir/**, etc. alone unless you also un-ignore something that exists inside that directory. Omit the asterisk or you could permanently lose a lot of data from certain invocations of git gc, git stash and more.

I don't really know what tmp/**/* is meant to do. I initially thought it could be used to match files in the sub-directories of tmp/ but not files directly present in tmp/ itself. But a simple test seems to suggest that this ignores all files in tmp/.

这篇关于.gitignore语法:bin vs bin / vs bin / * vs bin / **的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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